Runtime error calling functions on .Section

This template code worked fine in 0.64.*.

{{ $ancestor := .Section.IsAncestor .CurrentPage }}

In 0.65.1, though, when this partial is included in a 404 template, I get: error calling IsAncestor: runtime error: invalid memory address or nil pointer dereference

Presumably this is due to how sections are handled? In any case, I’m having a tough time debugging it. I tried swapping over to this:

{{ if ne .Section nil }}
    {{ $ancestor := .Section.IsAncestor .CurrentPage }}
{{ end }}

But that gives the same error, which I can’t quite follow – if .Section is nil, the assignment code shouldn’t be run, correct?

I may simply be messing up the template syntax, but it’s not obvious to me as to where. Any help would be appreciated.

1 Like

Yap. I have the same problem. I think it is a combination having a custom 404.html and calling page variables. There is already an issue v0.65.0 breaks breadcrumb snippet

1 Like

I’m still seeing the same error on 0.65.2, so I think this is a different bug…


I’m sorry about this breakage, but it’s all for a greater good. I fixed the .Parent vs 404 and other such “standalone pages”, but I didn’t check the other related methods (.IsAncestors etc.) Sadly we did not have any tests covering it and none of the many sites I tested with caught this issue.

I will fix this early next week.

Thanks for your responsiveness, @bep! No worries; I know how hard it can be to find these edge cases before stuff is out in the wild. Glad it’s tracked down, and looking forward to checking out the new functionality in in 0.65.*!

1 Like

I think the docsy theme is seeing something similar. See

I will make sure to test that theme as part of this fix. Sorry for the noise.

1 Like

I have maybe the same problem.

.FirstSection.Permalink doesn’t worked so I changed it to .CurrentSection.FirstSection and finally Hugo doesn’t spit out the error message

I checked that when using .FirstSection.Permalink in version 0.65.2, Hugo get error and when using .CurrentSection.FirstSection.Permalink in all version except 0.65.2, Hugo get error.
So I had to check Hugo version like this

{{ if eq hugo.Version "0.65.2" }}{{ .CurrentSection.FirstSection.Permalink }}{{ else }}{{ .FirstSection.Permalink }}{{ end }}

Hello @zzo

There is no need to do that.

Commit fixed the problem and it will be available in the next Hugo version.

1 Like