Thanks to visit codestin.com
Credit goes to GitHub.com

Skip to content

Conversation

@simonheimlicher
Copy link
Contributor

Summary

Fixes #14419

When {{ with partial "foo" }} returns a falsy value (false, nil, ""), the with block is skipped but _popPartialDecorator was only called inside the with block. This left an orphan entry on the decorator stack, causing "partial decorator ID mismatch" panic on subsequent partial calls.

Reproduction: https://github.com/simonheimlicher/hugo-partial-decorator-mismatch

Root cause

In tpl/tplimpl/templatetransform.go, the handleWithPartial function transforms {{ with partial ... }} to include decorator push/pop calls. The push happens unconditionally (as part of the condition evaluation), but the pop was only inside the with block's List (truthy branch). When the partial returns falsy, the block is skipped and the pop never executes.

Fix

Add _popPartialDecorator call to the else branch (ElseList) of the with statement, ensuring the decorator stack is always balanced regardless of whether the partial returns truthy or falsy.

Test plan

  • New test TestDecoratorPartialFalsyReturn reproduces the exact bug pattern
  • Test passes with fix, panics without it
  • All existing decorator tests pass
  • Verified with reproduction site

AI assistance disclosure

This PR was written primarily by Claude Code with Opus 4.5. All generated code has been reviewed and understood by the contributor.

@simonheimlicher simonheimlicher force-pushed the partial-decorator-mismatch branch from f2f38a2 to 9749abf Compare January 23, 2026 19:47
@simonheimlicher
Copy link
Contributor Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is an excellent pull request. The problem of the decorator stack becoming unbalanced with falsy partial returns is clearly explained, and the root cause analysis is spot on. The fix, which involves adding a _popPartialDecorator call to the else branch of the with statement, is correct and robustly implemented by manipulating the template AST. The addition of TestDecoratorPartialFalsyReturn is particularly valuable, as it provides a specific regression test that reproduces the panic and validates the fix. The changes are well-contained and follow the existing code patterns. Great work!

@bep
Copy link
Member

bep commented Jan 23, 2026

I suggest you rebase this against the master. I have done some "spac savings" work in the CI in th master branch.

@simonheimlicher simonheimlicher force-pushed the partial-decorator-mismatch branch from 9749abf to fa9dc4f Compare January 23, 2026 22:42
@simonheimlicher
Copy link
Contributor Author

@bep It turned out that when running mage -v check locally on macOS 15 on a MacBook Pro M2, there is a segmentation fault. I have opened a PR to address the root cause #14421.
However, right now, GH Actions seem to fail due to chocolatey: [NuGet] Response status code does not indicate success: 504 (Gateway Time-out)

@bep
Copy link
Member

bep commented Jan 24, 2026

@simonheimlicher the other branch is merged.

When {{ with partial "foo" }} returns a falsy value (false, nil, ""),
the with block is skipped but _popPartialDecorator was only called
inside the with block. This left an orphan entry on the decorator
stack, causing "partial decorator ID mismatch" panic on subsequent
partial calls.

Add _popPartialDecorator call to the else branch to ensure the
decorator stack is always balanced regardless of the partial's
return value.

Fixes gohugoio#14419
@simonheimlicher simonheimlicher force-pushed the partial-decorator-mismatch branch from fa9dc4f to d238712 Compare January 24, 2026 14:57
@simonheimlicher simonheimlicher marked this pull request as ready for review January 24, 2026 15:41
@gemini-code-assist
Copy link

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

@github-actions
Copy link

AI Detection Analysis 🔍

Confidence Score: 95%

Reasoning: The language, structure, and thoroughness of the pull request strongly suggest AI generation, particularly by a capable coding assistant like Claude Code. The PR exhibits characteristics of high-level summarization, consistent formatting, and inline documentation that are hallmarks of well-crafted AI-generated content. The disclosure explicitly mentions that Claude Code was used for the PR, though the author claims to have reviewed the output. Even without the disclosure, the overall writing style and comprehensive details align closely with outputs typically produced by sophisticated AI models trained on technical documentation and codebases.

Key Indicators:

  • AI Disclosure: The pull request contains an "AI assistance disclosure" section that states it was "written primarily by Claude Code with Opus 4.5." This is a direct admission of AI involvement.
  • Technical Clarity and Structure: The explanation of the bug, including the root cause, fix, and test plan, is structured in a highly methodical and dispassionate way characteristic of AI-generated content.
  • Consistent Verbosity and Tone: The documentation uses precise, consistent technical language without deviation, which is a common AI writing trait.
  • Inline comments: Detailed code comments that explain changes in a clear, didactic tone are typical for AI assistance, especially when paired with code generation tools like Claude.
  • Formatting Precision: Use of markdown headings, bullet lists, and code snippet formatting is exceptionally clean and uniform — often more so than seen in human-authored PRs unless heavily edited.

While the human review and submission are likely, the primary content appears AI-generated based on the above indicators.

⚠️ Warning: High confidence that this PR was generated by AI

@bep bep merged commit f472dd4 into gohugoio:master Jan 24, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tpl: Panic "partial decorator ID mismatch" when partial returns falsy value

2 participants