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

Overlapping cascade rules are applied in nondeterministic order #12594

Open
nelhage opened this issue Jun 11, 2024 · 3 comments
Open

Overlapping cascade rules are applied in nondeterministic order #12594

nelhage opened this issue Jun 11, 2024 · 3 comments
Assignees
Labels
Milestone

Comments

@nelhage
Copy link

nelhage commented Jun 11, 2024

If multiple cascade rules match the same page, they are applied in arbitrary order according to Go map iteration order, resulting in nondeterminstic builds and extremely confusing behavior.

Context

I wanted to create a /drafts/ section on my site, with the behavior that posts there would be published to production so I could share them for review, but would only be listed locally, to discourage stumbling across them.

After some experimentation, I determined that the following content/drafts/_index.md appeared to work as desired; I speculated that overlapping cascade rules were applied in a "first-match-wins" order.

---
cascade:
- _target:
    environment: development
  build:
    list: always
- build:
    list: never
---

However, the above only mostly works; I soon discovered that sometimes posts would be excluded from the page list in development.

The bug

It turns out that rules are applied in an arbitrary order, according to Go map iteration order. In practice -- for my build of hugo -- this results in mostly consistent behavior, which is what made the behavior so confusing.

Reproducer

I've pushed a minimal demo to github:

$ git clone https://github.com/nelhage/hugo-cascade-order
$ cd hugo-cascade-order
# Render 100 times, and count how many pages appear in the RSS feed each time.
# The correct answer should be 20
$ { for _ in {1..100}; do hugo --quiet --environment development && grep -c '<title>Page' public/post/index.xml; done } | sort | uniq -c | sort -rn
  26 17
  20 18
  18 19
  12 15
  11 16
  10 20
   2 14
   1 12

You can see that links are generated and included in the page list most of the time, but that typically 1-3 pages are dropped. Go deliberately injects entropy into the map iteration order, but apparently in this case it is mostly deterministic.

Comment

The issue can be worked around in user sites by eliminating overlapping cascade rules -- e.g. I have worked around using

---
cascade:
- _target:
    environment: development
  build:
    list: always
- _target:
    environment: '{staging,production}'
  build:
    list: never
---

However, I still regard this behavior as a bug due to how profoundly confusing and unexpected it is. cascade: rules are present in the source as a list, and so IMO it's very reasonable to expect them to be processed in that order.

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

$ hugo version
hugo v0.125.5+extended darwin/arm64 BuildDate=unknown VendorInfo=nixpkgs

Does this issue reproduce with the latest release?

Yes

@bep bep removed the NeedsTriage label Jun 12, 2024
@bep bep added this to the v0.128.0 milestone Jun 12, 2024
@bep bep modified the milestones: v0.128.0, v0.129.0 Jun 21, 2024
@nick2432
Copy link

can i work on this

@bep bep assigned nick2432 and unassigned nick2432 Jul 20, 2024
@bep
Copy link
Member

bep commented Jul 20, 2024

@nick2432 this issue isn't very straight forward, so I would prefer to do this myself.

@bep bep self-assigned this Jul 20, 2024
@nick2432
Copy link

@nick2432 this issue isn't very straight forward, so I would prefer to do this myself.

can you suggest any other good first issue or simple issue?

@bep bep modified the milestones: v0.129.0, v0.131.0 Jul 22, 2024
@bep bep modified the milestones: v0.131.0, v0.133.0 Aug 9, 2024
@bep bep modified the milestones: v0.133.0, Unscheduled Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants