argoproj / argoproj/argo-workflows

`inputs` or `workflow` is nil when used in sprig expression that has more than 1 parameter (`withParam` loop)

Open
#8,224 38 comments 24 reactions 0 assignees View on GitHub
area/templating P1
Dominant language
Go
Stars
17k
Forks
3.7k
Avg merge
1d 20h
Merged PRs (30d)
138

Description

## Checklist

* [x] Double-checked my configuration.
* [x] Tested using the latest version.
* [x] Used the Emissary executor.

## Summary

### What happened/what you expected to happen?

With the following context:
* within a `withParam` loop
* in `argument.parameter.value`
* using a `sprig` function that as more than 1 parameter (e.g. `sprig.replace`)
* referencing `workflow.parameters.paramX` or `inputs.parameters.paramX`

Then, the following error is thrown:
```
Warning WorkflowFailed 3s workflow-controller failed to evaluate expression: cannot fetch parameters from (1:23)
| sprig.replace(inputs.parameters.paramX, 'YYY', 'Replace XXX')
| ......................^
```

If the expression uses a sprig function with 1 parameter, then the error doesn't occur.

### What version are you running?
`3.3.0`

## Diagnostics

Paste the smallest workflow that reproduces the bug. We must be able to run the workflow.

```yaml
---
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: my-template
namespace: argo
spec:
entrypoint: execute

arguments:
parameters:
- name: paramX
value: XXX
- name: paramY
valueFrom:
configMapKeyRef:
name: my-config
key: my-key

templates:
- name: execute
steps:
- - name: other-template
templateRef:
name: other-template
template: execute
withParam: "{{workflow.parameters.paramY}}"
arguments:
parameters:
- name: my-param
value: "{{= sprig.replace(workflow.parameters.paramX, "YYY", "Replace XXX" }}"
```

All the following are however working and are producing the expected values:
```yaml
parameters:
- name: my-param
value: "{{ workflow.parameters.paramX }}"
```
```yaml
parameters:
- name: my-param
value: "{{= workflow.parameters.paramX }}"
```
```yaml
parameters:
- name: my-param
value: "{{= sprig.trim(workflow.parameters.paramX) }}"
```

---

**Message from the maintainers**:

Impacted by this bug? Give it a 👍. We prioritise the issues with the most 👍.

Contributor guide

Open the contributing guide

Research direction

Start by running the minimal WorkflowTemplate with a withParam loop and the sprig.replace expression in argument.parameter.value, then trace workflow-controller expression evaluation for workflow.parameters and inputs.parameters. Done means multi-parameter Sprig expressions resolve those values inside the loop without a nil-parameter error and preserve the expected replacement result.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.