Fix IB ineligibility reason serialization#4380
Merged
cjdsellers merged 2 commits intoJul 5, 2026
Merged
Conversation
17d7452 to
78937c8
Compare
Newer IB Gateway versions may return ineligibilityReasonList populated
with ibapi.ineligibility_reason.IneligibilityReason objects in
contractDetails. _serialize_for_json() only handled Decimal/Enum and
passed other objects through unchanged, so persisting the instrument
to a cache database (Redis/msgpack) raised:
TypeError: Encoding objects of type
<class 'ibapi.ineligibility_reason.IneligibilityReason'>
is unsupported
_serialize_for_json() now checks primitive types first, then converts
arbitrary objects with __dict__ via vars() recursively (reusing the
existing dict branch), falling back to str() for anything else. Adds
a regression test that reproduces the original TypeError and verifies
the fix, and a RELEASES.md entry.
f6a6d0c to
8f21434
Compare
cjdsellers
approved these changes
Jul 5, 2026
cjdsellers
left a comment
Member
There was a problem hiding this comment.
Thank you for the fix @xxxxxx-oss
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.
Pull Request
NautilusTrader prioritizes correctness and reliability, please follow existing patterns for validation and testing.
CONTRIBUTING.mdand followed the established practicesSummary
Newer IB Gateway versions may populate
contractDetails.ineligibilityReasonListwithibapi.ineligibility_reason.IneligibilityReasonobjects, which_serialize_for_json()did not sanitize — passing them straight through and breaking downstream msgpack/JSON
serialization (e.g. when persisting an instrument to a cache database).
This PR extends
_serialize_for_json()with a fallback that converts objects exposing__dict__viavars()recursively, and falls back tostr()for anything else. Adds aregression test that reproduces the original
TypeErrorand verifies the fix.Related Issues/PRs
N/A
Type of change
Breaking change details (if applicable)
N/A
Documentation
docs/developer_guide/docs.md)Release notes
RELEASES.mdthat follows the existing conventions (when applicable)Testing
Ensure new or changed logic is covered by tests.
Added
test_contract_details_to_dict_serializes_ineligibility_reason_objectsintests/integration_tests/adapters/interactive_brokers/test_parsing.py, which reproduces theoriginal
TypeErroragainst the unfixed code path and asserts the fixed output round-tripsthrough
msgspec.msgpack.