Repository navigation
fix(v1): treat JSON null CloudEvent attributes as omitted - #327
Closed
ekanshbannsal wants to merge 3 commits into
Closed
ekanshbannsal wants to merge 3 commits into
ekanshbannsal wants to merge 3 commits into
Conversation
Signed-off-by: Ekansh Bannsal <ekanshbannsal@gmail.com>
There was a problem hiding this comment.
🟡 Changes recommended
Null required attributes bypass validation, allowing an event with "id": null to be accepted and silently assigned a new ID instead of rejected as missing a required field.
1 open issue
What changed in this PR
Updates the v1 compatibility layer to treat null non-data JSON attributes as omitted, addressing the serialization behavior related to #199.
Changes:
- Skips null non-data attributes during JSON deserialization.
- Omits extension attributes valued
Noneduring JSON serialization. - Adds regression coverage for spec versions 0.3 and 1.0, including preservation of null data.
| File | Description |
|---|---|
tests/test_v1_compat/test_http_conversions.py |
Tests null-versus-omitted JSON attribute equivalence for both spec versions. |
src/cloudevents/v1/sdk/event/base.py |
Filters null attributes during JSON serialization and deserialization. |
Review effort: Balanced
Comment on lines
+238
to
+239
| if value is None and name not in ("data", "data_base64"): | ||
| continue |
Signed-off-by: Ekansh Bansal <ekanshbannsal@gmail.com>
Member
|
I don't think this change should be merged at all. this PR addresses v1 compatibility layer that overall should not be used and is kept in the SDK as a good gesture. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Related Issue: #199
Type of change:
Description:
Aligns
v1.sdk.event.base.BaseEventJSON serialization and deserialization with the CloudEvents JSON format specification (cloudevents.core.formats.json.JSONFormat.read), treating non-data attributes with valuenull(None) as omitted:BaseEvent.UnmarshalJSON, skip attributes wherevalue is None and name not in ("data", "data_base64")instead of setting them asNone(which raisedAttributeErrorwhen marshaling HTTP headers or leakedNoneintoextensions).BaseEvent.MarshalJSON, omit extension attributes whose value isNone.test_json_null_attribute_equivalent_to_omittedintests/test_v1_compat/test_http_conversions.pyverifying parity for both0.3and1.0spec versions.Pre-submission checklist:
git commit --signoff.pytest(571 passed),ruff check, andmypy src/cloudevents/v1/sdk/event/base.py.