argoproj / argoproj/argo-workflows
expression template with 'in' operator fails when withParam item is missing a key
- Dominant language
- Go
- Stars
- 17k
- Forks
- 3.7k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 138
Description
### Pre-requisites
- [x] I have double-checked my configuration
- [x] I have tested with the `:latest` image tag (i.e. `quay.io/argoproj/workflow-controller:latest`) and can confirm the issue still exists on `:latest`. If not, I have explained why, **in detail**, in my description below.
- [x] I have searched existing issues and could not find a match for this bug
- [ ] I'd like to contribute the fix myself (see [contributing guide](https://github.com/argoproj/argo-workflows/blob/main/docs/CONTRIBUTING.md))
### What happened? What did you expect to happen?
When using `withParam` with heterogeneous JSON items (some items missing certain keys), expression templates using the `in` operator to guard against missing keys fail with:
```
failed to evaluate expression: item.bucket is missing
```
The expression is intended to safely handle missing fields:
```
{{= 'bucket' in item ? item['bucket'] : ''}}
```
### Version(s)
v4.0.4
### Paste a minimal workflow that reproduces the issue. We must be able to run the workflow; don't enter a workflow that uses private images.
```YAML
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: item-missing-field-
spec:
entrypoint: main
templates:
- name: main
steps:
- - name: process
template: process-item
withParam: |
[
{"type": "s3", "bucket": "my-bucket"},
{"type": "nextcloud"}
]
arguments:
parameters:
- name: s3_bucket
value: "{{= 'bucket' in item ? item['bucket'] : ''}}"
- name: process-item
inputs:
parameters:
- name: s3_bucket
value: ""
container:
image: alpine
command: [echo]
args: ["{{inputs.parameters.s3_bucket}}"]
```
### Logs from the workflow controller
```text
kubectl logs -n argo deploy/workflow-controller | grep ${workflow}
```
### Logs from in your workflow's wait container
```text
kubectl logs -n argo -c wait -l workflows.argoproj.io/workflow=${workflow},workflow.argoproj.io/phase!=Succeeded
```
Contributor guide
Research direction
Start by running the minimal workflow in the issue and trace expression-template evaluation for the withParam item that lacks bucket. Confirm the fix preserves the conditional behavior for both heterogeneous JSON items and verify the workflow completes with an empty value for the missing key.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, kubernetes
- Domain
- backend, devops
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 56/100