Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to detect nil explicitly in conditionals #5905

Closed
RealOrangeOne opened this issue Apr 27, 2019 · 7 comments · Fixed by #5909
Closed

Unable to detect nil explicitly in conditionals #5905

RealOrangeOne opened this issue Apr 27, 2019 · 7 comments · Fixed by #5909

Comments

@RealOrangeOne
Copy link
Contributor

After the last update to 0.55, i'm no longer able to specify if a value is equal to nil. This is especially useful when combined with where. https://gohugo.io/functions/where/#unset-fields defines this as possible, although the example is using .Params, which I guess behaves slightly differently.

For example, given a page

<p>{{ .Parent }}</p>
<p>{{ eq .Parent nil }}</p>
<p>{{ .File }}</p>
<p>{{ .Permalink }}</p>

yields

<nil>
false
tags/arch/_index.md
http://localhost:1313/tags/arch/

Doing {{ if .Parent }} acts false, as expected, meaning it seems nil != nil in this new release.

After some naive researching, https://dev.to/pauljlucas/go-tcha-when-nil--nil-hic might have something to do with this?

@RealOrangeOne
Copy link
Contributor Author

Thanks for such a quick fix @bep, but this doesn't appear to be fixed. Or at least it's not in Hugo Static Site Generator v0.55.6/extended linux/amd64 BuildDate: unknown

The below code:

{{ range where .Site.Pages.ByTitle ".Parent" "!=" nil }}
        <p>{{ .Parent }} {{ eq .Parent nil }}</p>
{{ end }}

yields many lines with <nil> false. The pages affected seem to all be either taxonomy / taxonomy terms, if that helps anything.

My current fix is to do:

{{ range .Site.Pages.ByTitle }}
  {{ if .Parent }}
    <p>{{ .Parent }}</p>
  {{ end }}
{{ end }}

Which makes me think it is probably caused by the fun which is nil equality checking in Go!

@bep
Copy link
Member

bep commented Jun 1, 2019

I don't watch closed issues. Which isn't a way to say that all closed issues are fixed, they're just not on my radar anymore.

@RealOrangeOne
Copy link
Contributor Author

@bep ok, what's the process for getting this issue looked into again? Re-opening the issue, or making a new one?

I'd argue there's definitely still a bug here.

@bep
Copy link
Member

bep commented Jun 2, 2019

Making a new one.

@bep
Copy link
Member

bep commented Jun 2, 2019

Note that the issue described in the first comment is fixed.

@RealOrangeOne
Copy link
Contributor Author

RealOrangeOne commented Jun 3, 2019

image

It definitely isn't. But anyway, new issue opened: #6015

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants