Skip to content

fix: add a special case for item variable during global expression replacement#15033

Merged
Joibel merged 7 commits intoargoproj:mainfrom
elliotgunton:fix-sprig-expression-issue
Nov 12, 2025
Merged

fix: add a special case for item variable during global expression replacement#15033
Joibel merged 7 commits intoargoproj:mainfrom
elliotgunton:fix-sprig-expression-issue

Conversation

@elliotgunton
Copy link
Member

@elliotgunton elliotgunton commented Nov 12, 2025

Fixes #15008

Motivation

  • The root cause of the issue was from SubstituteParams, where the globalReplacedTmplStr would have already lost the ={{sprig.func(item)}} expression which became an empty string. This meant the later processItem function had no expression to expand.
  • This seems to have come from a change in sprig which in turn came from the expr library upgrade from 1.16 to 1.17 in 9b7c0c4

Modifications

  • We now have a special case to not attempt to run the expr program as an unresolved item in a sprig string function now comes back as an empty string, instead of nil.
  • As part of this change, refactored the anyVarNotInEnv to return the varname that is missing as a reference to a string, or nil.
  • Also removed a completely unused function hasRetries and refactored and expanded the unit tests where it was used
  • Added an e2e test using the workflow from the issue

Verification

  • e2e test added using the workflow from the issue
  • Also tested manually.

@elliotgunton elliotgunton force-pushed the fix-sprig-expression-issue branch from 91fc59e to 98df7eb Compare November 12, 2025 12:28
…replacement

* The root cause of the issue was from SubstituteParams, where the
  `globalReplacedTmplStr` would have already lost the `={{sprig.func(item)}}`
  expression which became an empty string. This meant the later `processItem`
  function had no expression to expand.
* This seems to have come from a change in sprig which in turn came from
  the `expr` library upgrade from 1.16 to 1.17 in 9b7c0c
* We now have a special case to _not_ attempt to run the `expr` program
  as an unresolved `item` in a sprig string function now comes back as an
  empty string, instead of `nil`.

Signed-off-by: Elliot Gunton <elliotgunton@gmail.com>
Signed-off-by: Elliot Gunton <elliotgunton@gmail.com>
Signed-off-by: Elliot Gunton <elliotgunton@gmail.com>
@elliotgunton elliotgunton force-pushed the fix-sprig-expression-issue branch 2 times, most recently from 1a15f08 to af89a1c Compare November 12, 2025 14:38
@elliotgunton elliotgunton marked this pull request as ready for review November 12, 2025 14:41
Signed-off-by: Elliot Gunton <elliotgunton@gmail.com>
@elliotgunton elliotgunton force-pushed the fix-sprig-expression-issue branch from af89a1c to 44480a2 Compare November 12, 2025 14:47
@elliotgunton elliotgunton requested a review from Joibel November 12, 2025 14:48
@elliotgunton elliotgunton added cherry-pick/3.6 cherry-pick/3.7 Cherry-pick this to release-3.7 labels Nov 12, 2025
Signed-off-by: Elliot Gunton <elliotgunton@gmail.com>
Copy link
Member

@Joibel Joibel left a comment

Choose a reason for hiding this comment

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

nits only

Signed-off-by: Elliot Gunton <elliotgunton@gmail.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where the item variable in sprig string functions (like sprig.upper(item)) was being incorrectly resolved to an empty string during global expression replacement, causing withItems loops to fail. The fix adds special handling for the item variable alongside existing special cases for retries, lastRetry.*, and workflow.* variables.

  • Refactored anyVarNotInEnv to check against a centralized list of variables and return the missing variable name
  • Consolidated multiple conditional checks into a single unified check with a variablesToCheck list
  • Removed unused hasRetries function and improved test coverage

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
util/template/expression_template.go Refactored variable checking logic to use a centralized list and unified handling for unresolved variables including item
util/template/expression_template_test.go Renamed and expanded test from Test_hasRetries to Test_hasVariableInExpression with additional test cases for item variable
test/e2e/expr_lang_test.go Added e2e regression test for issue #15008 and fixed typo in existing test suite name
Comments suppressed due to low confidence (1)

test/e2e/expr_lang_test.go:110

  • Corrected spelling from 'TestExprLangSSuite' to 'TestExprLangSuite' (removed duplicate 'S').

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Elliot Gunton <elliotgunton@gmail.com>
@elliotgunton elliotgunton requested a review from Joibel November 12, 2025 15:41
@Joibel Joibel enabled auto-merge (squash) November 12, 2025 15:50
@Joibel Joibel merged commit f4eef2b into argoproj:main Nov 12, 2025
39 checks passed
@argo-cd-cherry-pick-bot
Copy link

❌ Cherry-pick failed for 3.6. Please check the workflow logs for details.

@argo-cd-cherry-pick-bot
Copy link

❌ Cherry-pick failed for 3.7. Please check the workflow logs for details.

@elliotgunton elliotgunton deleted the fix-sprig-expression-issue branch November 12, 2025 16:39
Joibel pushed a commit that referenced this pull request Nov 12, 2025
…replacement (#15033)

(cherry picked from commit f4eef2b)

Signed-off-by: Elliot Gunton <elliotgunton@gmail.com>
Signed-off-by: Alan Clucas <alan@clucas.org>
Joibel pushed a commit that referenced this pull request Nov 13, 2025
…replacement (#15033)

(cherry picked from commit f4eef2b)

Signed-off-by: Elliot Gunton <elliotgunton@gmail.com>
Signed-off-by: Alan Clucas <alan@clucas.org>
Joibel pushed a commit that referenced this pull request Nov 13, 2025
…replacement (#15033)

(cherry picked from commit f4eef2b)

Signed-off-by: Elliot Gunton <elliotgunton@gmail.com>
Signed-off-by: Alan Clucas <alan@clucas.org>
Joibel added a commit that referenced this pull request Nov 13, 2025
…replacement (cherry-pick #15033 for 3.6) (#15040)

Signed-off-by: Elliot Gunton <elliotgunton@gmail.com>
Signed-off-by: Alan Clucas <alan@clucas.org>
Co-authored-by: Elliot Gunton <elliotgunton@gmail.com>
AnonyScorpio pushed a commit to AnonyScorpio/argo-workflows that referenced this pull request Nov 25, 2025
…replacement (cherry-pick argoproj#15033 for 3.7) (argoproj#15036)

Signed-off-by: Elliot Gunton <elliotgunton@gmail.com>
Signed-off-by: Alan Clucas <alan@clucas.org>
Co-authored-by: Elliot Gunton <elliotgunton@gmail.com>
guanguxiansheng pushed a commit to guanguxiansheng/argo-workflows that referenced this pull request Dec 15, 2025
…replacement (argoproj#15033)

Signed-off-by: Elliot Gunton <elliotgunton@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick/3.7 Cherry-pick this to release-3.7

Projects

None yet

Development

Successfully merging this pull request may close these issues.

item is not usable alone within a sprig expression since 3.6.7

3 participants