Skip to content

fix: avoid incomplete discriminators during deferred model builds - #1

Merged
speedysebi merged 1 commit into
mainfrom
fix/4036-discriminator-fields
Nov 5, 2026
Merged

speedysebi merged 1 commit into
mainfrom
fix/4036-discriminator-fields

Conversation

@speedysebi

Copy link
Copy Markdown
Owner

Summary

Fixes openai#4036 by reading Pydantic v2 discriminator literals and wire aliases from model_fields, which are available before a deferred core schema build finishes. The fallback decoder no longer caches a mapping that omitted a variant whose core schema was temporarily a definition reference.

Adds a deterministic regression test that exposes an unbuilt variant schema, checks that both discriminator values enter the cache, and checks that malformed data still constructs the correct variant.

Verification

  • pytest tests/test_models.py tests/test_streaming.py tests/test_response.py -q: 159 passed, 34 skipped
  • ruff check src/openai/_models.py tests/test_models.py: passed
  • ruff format --check src/openai/_models.py tests/test_models.py: passed
  • ty check: passed after adding tomli to the temporary local test environment
  • The regression test fails against unmodified main and passes with this change.

The issue's cold-process reproduction returned 0/20 failures on both unmodified main and this branch with Python 3.13/3.14 and Pydantic 2.12.5/2.13.5. The deterministic test exercises the incomplete-schema state directly.

@speedysebi
speedysebi merged commit b632727 into main Nov 5, 2026
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.

Concurrent first use of streaming decode caches an incomplete discriminator map, so events decode as the wrong class

1 participant