Repository navigation
Treat None dispatch fields as defaults in encode_dict for types 6/8/24 - #231
Merged
Merged
Conversation
A dict produced by asdict() of a truncated type 6, 8 or 24 message carries None for the fields that were not present in the payload. The create() dispatchers of these types called int() directly on dac/fid (6, 8), wmo (8 DAC1 FID21) and mmsi/partno (24), so encode_dict(decode(x).asdict()) raised a plain TypeError instead of encoding the message. Route those reads through a small helper that treats None like a missing key, which is what the generic Payload.create() already does for every other field. Regression tests cover the truncated round trip for all three types and explicit None values. Fixes M0r13n#228 Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
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.
Fixes #228.
Problem
A dict produced by
asdict()of a truncated type 6, 8 or 24 message carriesNonefor the fields that were not present in the payload. Thecreate()dispatchers of these types callint()directly ondac/fid(6, 8),wmo(8 DAC 1 FID 21) andmmsi/partno(24), soThe generic
Payload.create()already treatsNoneas "use the default" for every other field; only the dispatch step was inconsistent.Change
_dispatch_int(kwargs, key, default=0): reads an integer dispatch field and treatsNonelike a missing key.MessageType6.create,MessageType8.create,MessageType8Dac1Fid21.create(wmo) andMessageType24.create(mmsi,partno). No behaviour change for present values;partno=Noneselects Part A like a missingpartnowould.decode → asdict → encode_dict → decode, type and MMSI preserved) and explicitNonedispatch fields. Both tests fail onmainbefore the fix.Verification
pytest tests/on main + this change: 544 passed, 1 skipped; the two remaining failures (test_tcp_server,test_tcp_stream.test_invalid_endpoint) are Windows-only (SIGALRM,0.0.0.0bind) and fail identically without this change.flake8andmypy --strict ./pyaisclean.🤖 Generated with Claude Code