diff --git a/baker/DatapageHelpers.ts b/baker/DatapageHelpers.ts index 7d847eca3b..2fde6fd727 100644 --- a/baker/DatapageHelpers.ts +++ b/baker/DatapageHelpers.ts @@ -189,9 +189,10 @@ export const resolveFaqsForVariable = ( export const getPrimaryTopic = async ( knex: KnexReadonlyTransaction, - datapageData: DataPageDataV2 + tags: string[] = [], + slug: string | undefined ) => { - const firstTopicTag = datapageData.topicTagsLinks?.[0] + const firstTopicTag = tags[0] if (!firstTopicTag) return undefined let topicSlug: string @@ -200,7 +201,7 @@ export const getPrimaryTopic = async ( } catch { await logErrorAndMaybeCaptureInSentry( new Error( - `Data page with slug "${datapageData.chartConfig.slug}" is using "${firstTopicTag}" as its primary tag, which we are unable to resolve to a tag in the grapher DB` + `Data page with slug "${slug}" is using "${firstTopicTag}" as its primary tag, which we are unable to resolve to a tag in the grapher DB` ) ) return undefined diff --git a/baker/GrapherBaker.tsx b/baker/GrapherBaker.tsx index d3d767af0c..3fe4ec26e9 100644 --- a/baker/GrapherBaker.tsx +++ b/baker/GrapherBaker.tsx @@ -204,7 +204,11 @@ export async function renderDataPageV2( grapher ?? {} ) - datapageData.primaryTopic = await getPrimaryTopic(knex, datapageData) + datapageData.primaryTopic = await getPrimaryTopic( + knex, + datapageData.topicTagsLinks, + grapher.slug + ) // Get the charts this variable is being used in (aka "related charts") // and exclude the current chart to avoid duplicates diff --git a/baker/MultiDimBaker.tsx b/baker/MultiDimBaker.tsx index d8ce6d86b2..130c6201a3 100644 --- a/baker/MultiDimBaker.tsx +++ b/baker/MultiDimBaker.tsx @@ -142,7 +142,7 @@ export async function renderMultiDimDataPageFromConfig({ const faqEntries = await getFaqEntries(knex, config, variableMetaDict) // PRIMARY TOPIC - const primaryTopic = await getPrimaryTopic(knex, config.topicTags?.[0]) + const primaryTopic = await getPrimaryTopic(knex, config.topicTags, slug) // Related research const relatedResearchCandidates =