Skip to content

fix(dumpkit): preserve renamed builtin keys in fields() (#2733) - #2740

Closed
pratyu2h wants to merge 1 commit into
JarryShaw:mainfrom
pratyu2h:fix/dumpkit-renamed-builtin-keys
Closed

pratyu2h wants to merge 1 commit into
JarryShaw:mainfrom
pratyu2h:fix/dumpkit-renamed-builtin-keys

Conversation

@pratyu2h

@pratyu2h pratyu2h commented Nov 3, 2026

Copy link
Copy Markdown

Please follow the guide below

  • Searched for similar pull requests
  • Followed the coding style
  • make test passes, and a test case covers the change

What is the purpose of your pull request?

  • ix — corrects a defect

Description of your pull request and other information

Resolves #2733.

When dumping an Info or subclass instance via ields(), keys that clash with builtin names are assigned to map and their original name is appended to builtin and excluded. Previously, ields() directly checked if key not in skip, which caused keys like 'items' on Info or 'packet' on a reassembled TCP Datagram to be dropped from the dump despite being explicitly defined.

This PR checks keymap.get(key, key) not in skip where keymap = getattr(info, 'map', {}). This ensures renamed builtin keys are kept in the dumped output under their original name while still excluding regular excluded attributes. Added unit test in ests/dumpkit/test_common_unit.py.

Signed-off-by: pratyu2h <pratyush07sharma@gmail.com>
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Nov 3, 2026
@github-actions github-actions Bot added this to the PyPCAPKit v1.6 milestone Nov 3, 2026
@JarryShaw

Copy link
Copy Markdown
Owner

Thanks for picking this up. NEEDS CHANGES, and it overlaps with #2736, which was opened earlier for #2733 and has been reviewed.

  • fields() is fixed, but to_dict() still records the original list in __excluded__. So dumper(info.to_dict()) and the nested branch of object_hook still drop the renamed key.
  • A real reassembled datagram's packet is a deferred protocol object, not bytes. Dumped as is, it writes the protocol's internals, including an _io.BytesIO address. That makes dumps differ from run to run, which fix(dumpkit): dump a key renamed for clashing with a builtin under its own name (#2733) #2736 avoids by writing the object's .info.
  • The edited fields() docstring lost the end of its sentence: "…when written." now runs into "The keys…".

Which PR to take is the maintainer's call.

@JarryShaw JarryShaw added bug Issues reporting a defect (set by the bug report template; a default, not an assessment) duplicate Issues or pull requests already covered by another; closed with a pointer to it labels Nov 3, 2026
@pratyu2h

pratyu2h commented Nov 3, 2026

Copy link
Copy Markdown
Author

Thank you for the detailed review and guidance @JarryShaw! Closing this PR in favor of #2736.

@pratyu2h pratyu2h closed this Nov 3, 2026
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Nov 3, 2026
@github-actions github-actions Bot removed this from the PyPCAPKit v1.6 milestone Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issues reporting a defect (set by the bug report template; a default, not an assessment) duplicate Issues or pull requests already covered by another; closed with a pointer to it

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(dumpkit): a key renamed for clashing with a builtin is dropped from the dump

2 participants