Skip to content

fix: handle null values properly in trigger payload construction#3738

Merged
whynowy merged 2 commits intoargoproj:masterfrom
puretension:fix/null-values-invalid-json-3719
Oct 17, 2025
Merged

fix: handle null values properly in trigger payload construction#3738
whynowy merged 2 commits intoargoproj:masterfrom
puretension:fix/null-values-invalid-json-3719

Conversation

@puretension
Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes the issue where null values in trigger payloads create invalid JSON. The getValueByKey function now
properly handles gjson.Null types by returning the raw "null" string instead of an empty string.

Motivation

Fixes #3719 - When a trigger defines a payload with a source value that is null, the JSON passed as the
trigger payload becomes invalid (e.g., {"nullable_key": ,} instead of {"nullable_key": null}). This
breaks JSON parsing in downstream systems.

Describe how you validated your changes

• Added comprehensive unit tests for null value handling in TestGetValueByKey_NullValue
• Added integration test TestConstructPayload_NullValue to verify end-to-end null value preservation
• All existing tests continue to pass
• Verified that the generated JSON is valid and contains proper null values

Additional Notes

The fix specifically handles the gjson.Null type by returning res.Raw (which contains "null") instead of
res.String() (which returns empty string for null values). This ensures JSON validity while preserving
the semantic meaning of null values.

- Fix getValueByKey to return raw 'null' for null JSON values
- Prevent invalid JSON generation when null values are present
- Add comprehensive tests for null value handling

Fixes argoproj#3719

Signed-off-by: puretension <rlrlfhtm5@gmail.com>
@puretension puretension force-pushed the fix/null-values-invalid-json-3719 branch from eafb47f to 466a8bd Compare September 18, 2025 18:43
Copy link
Copy Markdown
Member

@whynowy whynowy left a comment

Choose a reason for hiding this comment

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

Thanks

@whynowy whynowy enabled auto-merge (squash) October 17, 2025 15:40
@whynowy whynowy merged commit a4a7050 into argoproj:master Oct 17, 2025
7 checks passed
@elventear
Copy link
Copy Markdown
Contributor

Thank you!

whynowy pushed a commit that referenced this pull request Nov 3, 2025
Signed-off-by: puretension <rlrlfhtm5@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Triggers with null values create invalid JSON

3 participants