-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
tpl: Fix partial decorator panic when partial returns falsy #14420
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
tpl: Fix partial decorator panic when partial returns falsy #14420
Conversation
f2f38a2 to
9749abf
Compare
|
/gemini review |
There was a problem hiding this 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!
|
I suggest you rebase this against the master. I have done some "spac savings" work in the CI in th master branch. |
9749abf to
fa9dc4f
Compare
|
@bep It turned out that when running |
|
@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
fa9dc4f to
d238712
Compare
Using Gemini Code AssistThe 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
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 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. |
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:
While the human review and submission are likely, the primary content appears AI-generated based on the above indicators. |
Summary
Fixes #14419
When
{{ with partial "foo" }}returns a falsy value (false,nil,""), thewithblock is skipped but_popPartialDecoratorwas only called inside thewithblock. 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, thehandleWithPartialfunction 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 thewithblock's List (truthy branch). When the partial returns falsy, the block is skipped and the pop never executes.Fix
Add
_popPartialDecoratorcall to the else branch (ElseList) of thewithstatement, ensuring the decorator stack is always balanced regardless of whether the partial returns truthy or falsy.Test plan
TestDecoratorPartialFalsyReturnreproduces the exact bug patternAI 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.