Skip to content

fix(json): treat null attributes as omitted when decoding - #309

Merged
duglin merged 1 commit into
cloudevents:mainfrom
zhanghao0806:fix/json-null-attributes
Nov 16, 2026
Merged

duglin merged 1 commit into
cloudevents:mainfrom
zhanghao0806:fix/json-null-attributes

Conversation

@zhanghao0806

Copy link
Copy Markdown
Contributor

Description

Treat JSON envelope attributes whose value is null as omitted before version detection, time parsing, and event construction. The core JSON reader previously passed them to validation (or isoparse for time), rejecting JSON representations permitted by the specification.

Related to the JSON decoding distinction discussed in #199. This does not change Python object equality or in-memory attribute validation.

Specification: https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/formats/json-format.md#22-type-system-mapping

Validation

  • Before the fix: 11 new regression cases failed.
  • Full pytest -q: 886 passed, 18 xfailed.
  • Ruff lint/format and MyPy on both changed files: passed.
  • Covers optional context attributes and extension attributes, explicit and auto-detected factories, a custom factory, null payloads, and nested payload null/false/zero values.

Only top-level null values are removed; payload contents are preserved. Prepared with AI assistance; commits are signed off.

Signed-off-by: zhanghao <112082360+zhanghao0806@users.noreply.github.com>
@duglin
duglin force-pushed the fix/json-null-attributes branch from 9faf5e6 to 3636b23 Compare November 16, 2026 14:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the change to treat top-level null attributes as omitted during JSON decoding.

No open issues 🎉

What changed in this PR

Updates the core JSON decoder to treat top-level null attributes as omitted, aligning with CloudEvents JSON semantics. This addresses the decoding distinction related to #199 without changing Python object equality or in-memory validation.

Changes:

  • Filters null envelope values before version detection, time parsing, and event construction.
  • Adds regression coverage for automatic, explicit, and custom factories, while verifying that nested payload nulls, false values, and zeros are preserved.
File Description
tests/​test_core/​test_format/​test_json.py Tests null-attribute omission, factory handling, and payload preservation.
src/​cloudevents/​core/​formats/​json.py Removes top-level null values before processing the JSON envelope.

Review effort: Balanced

@duglin
duglin merged commit b495f1b into cloudevents:main Nov 16, 2026
19 checks passed
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.

3 participants