Skip to content

Omit absent Data when decoding DAG-PB - #58

Merged
acul71 merged 2 commits into
ipld:masterfrom
yashksaini-coder:fix/dag-pb-omit-absent-data
Nov 20, 2026
Merged

acul71 merged 2 commits into
ipld:masterfrom
yashksaini-coder:fix/dag-pb-omit-absent-data

Conversation

@yashksaini-coder

Copy link
Copy Markdown
Contributor

Fixes #56

  • _node_to_dict() in dag/codecs/dag_pb.py only sets "Data" when the block has it, so decode(b"") == {"Links": []}, matching go-codec-dagpb and @ipld/dag-pb. Encoding is unchanged.
  • test_no_data updated; new DagPbDataModelFormTestCase: empty block decodes without Data, present Data kept, the decoded dagpb_empty re-encodes to the fixture's DAG-CBOR and DAG-JSON CIDs, decode → encode round-trip.

pytest: 197 passed (4 tests fail on master). pre-commit passes.

Compatibility: decoded["Data"] raises KeyError for blocks without Data; use .get("Data").

@acul71 acul71 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @yashksaini-coder — omitting absent Data on DAG-PB decode (instead of "Data": None) matches the spec and other implementations, with clear tests and a useful .get("Data") note. Fixes #56. LGTM.

@acul71
acul71 merged commit b46ecda into ipld:master Nov 20, 2026
22 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.

DAG-PB decode returns "Data": None instead of omitting Data

2 participants