Warning triggered by "File.TranslationBaseName" in "where" query

I have a function whose job is to return a file in the current language, but fall back to the default language if it can’t be found. An example of calling the partial is as follows:

{{ $bannerText := partial "functions/GetSection" (dict "sectionName" "announcement-banner" "Page" .Page) }}

And the function itself looks like this:

{{ $sectionName := .sectionName }}
{{ $section := (where (where .Page.Site.RegularPages "File.Dir" "in" (slice "_content-components\\" "_content-components/")) "File.TranslationBaseName" $sectionName) }}
{{ range .Page.Site.Home.Translations }}
	{{ $section = $section | lang.Merge (where .Page.Site.RegularPages "File.TranslationBaseName" $sectionName) }}
{{ end }}
{{ return index $section 0 }}

Whenever I build my site, I get a warning:

WARN 2023/02/14 16:19:30 .File.TranslationBaseName on zero object. Wrap it in if or with: {{ with .File }}{{ .TranslationBaseName }}{{ end }}

The only place in my code using .File.TranslationBaseName is the function above, but I’m not sure of how to refactor such that I can silence that warning.

Any recommendations?

One of the pages rendered by the template that calls the partial is not backed by a file.

You need to code defensively:

{{ if .File }}

Apologies if this should be obvious, but how do I do that kind of check given that it’s part of a where query?

Which template or templates call the partial? The whole chain, not just the last in line.

Also, what does your content structure look like? Please post the output from tree content.

In pulling the information requested above, I wanted to ensure that the cause was in fact the partial referenced in my initial post (the only instance in my code which references TranslationBaseName). I removed that partial entirely, and rebuilt, but the warning persists. Is .File.TranslationsBaseName implicitly used in other Hugo functions?

I’ve seen some unexpected messages referencing .File. This is the one that I remember:

Aha. That’s a good lead as I have a similar permalink structure. Will investigate further. Thank you!