Skip to content

Fix IB ineligibility reason serialization#4380

Merged
cjdsellers merged 2 commits into
nautechsystems:developfrom
xxxxxx-oss:fix/ib-ineligibility-reason-serialization
Jul 5, 2026
Merged

Fix IB ineligibility reason serialization#4380
cjdsellers merged 2 commits into
nautechsystems:developfrom
xxxxxx-oss:fix/ib-ineligibility-reason-serialization

Conversation

@xxxxxx-oss

Copy link
Copy Markdown
Contributor

Pull Request

NautilusTrader prioritizes correctness and reliability, please follow existing patterns for validation and testing.

  • I have reviewed the CONTRIBUTING.md and followed the established practices

Summary

Newer IB Gateway versions may populate contractDetails.ineligibilityReasonList with
ibapi.ineligibility_reason.IneligibilityReason objects, 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__ via vars() recursively, and falls back to str() for anything else. Adds a
regression test that reproduces the original TypeError and verifies the fix.

Related Issues/PRs

N/A

Type of change

  • Bug fix (non-breaking)
  • New feature (non-breaking)
  • Improvement (non-breaking)
  • Breaking change (impacts existing behavior)
  • Documentation update
  • Maintenance / chore

Breaking change details (if applicable)

N/A

Documentation

  • Documentation changes follow the style guide (docs/developer_guide/docs.md)

Release notes

  • I added a concise entry to RELEASES.md that follows the existing conventions (when applicable)

Testing

Ensure new or changed logic is covered by tests.

  • Affected code paths are already covered by the test suite
  • I added/updated tests to cover new or changed logic

Added test_contract_details_to_dict_serializes_ineligibility_reason_objects in
tests/integration_tests/adapters/interactive_brokers/test_parsing.py, which reproduces the
original TypeError against the unfixed code path and asserts the fixed output round-trips
through msgspec.msgpack.

@CLAassistant

CLAassistant commented Jul 4, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@xxxxxx-oss xxxxxx-oss force-pushed the fix/ib-ineligibility-reason-serialization branch 2 times, most recently from 17d7452 to 78937c8 Compare July 4, 2026 12:18
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.
@xxxxxx-oss xxxxxx-oss force-pushed the fix/ib-ineligibility-reason-serialization branch from f6a6d0c to 8f21434 Compare July 5, 2026 04:22
@cjdsellers cjdsellers changed the title Fix/ib ineligibility reason serialization Fix IB ineligibility reason serialization Jul 5, 2026

@cjdsellers cjdsellers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the fix @xxxxxx-oss

@cjdsellers cjdsellers merged commit 4d3b547 into nautechsystems:develop Jul 5, 2026
25 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