Skip to content

Unexpected behavior of "where ... not in" with empty slice #13621

Closed
@AlanBreck

Description

@AlanBreck

I'm encountering an unexpected behavior when using not in with an empty slice in a where condition.

Non-empty slice:

{{- $pages := where site.RegularPages "Kind" "not in" (slice "section") -}}
{{ printf "#%v" $pages }} --> Pages(1)

Empty slice:

{{- $pages := where site.RegularPages "Kind" "not in" (slice) -}}
{{ printf "#%v" $pages }} --> Pages(0)

By contrast, I see an expected result when using the not and collections.In functions outside of a where condition:

{{ printf "%#v" (not (in $forbiddenFruits "pineapple")) }} --> true
{{ printf "%#v" (not (in $forbiddenFruits "apple")) }} --> false
{{ printf "%#v" (not (in slice "pineapple")) }} --> true

https://discourse.gohugo.io/t/where-not-in-with-empty-slice/54409

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.145.0+extended+withdeploy darwin/arm64 BuildDate=2025-02-26T15:41:25Z VendorInfo=brew

Does this issue reproduce with the latest release?

Unsure

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions