Skip to content

Conversation

puretension
Copy link

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 <[email protected]>
@puretension puretension force-pushed the fix/null-values-invalid-json-3719 branch from eafb47f to 466a8bd Compare September 18, 2025 18:43
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
1 participant