Skip to content

Conversation

@Natim
Copy link

@Natim Natim commented Oct 27, 2025

  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Please using Annotated[Union] with Python 3.14

Additional context & links

Fixed #2704 to work properly with Python 3.14

@Natim Natim requested a review from a team as a code owner October 27, 2025 17:33
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 694 to +697
discriminator_field=discriminator_field_name,
discriminator_alias=discriminator_alias,
)
cast(CachedDiscriminatorType, union).__discriminator__ = details
cast(CachedDiscriminatorType, Annotated[union, details])

Choose a reason for hiding this comment

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

P1 Badge Restore caching of union discriminator metadata

The new code replaces cast(CachedDiscriminatorType, union).__discriminator__ = details with a bare cast(CachedDiscriminatorType, Annotated[union, details]). This only constructs an Annotated type and discards it, so the union instance never receives a __discriminator__ attribute. Subsequent calls to _build_discriminated_union_meta will therefore never hit the isinstance(union, CachedDiscriminatorType) fast path and tests that expect UnionType.__discriminator__ to exist (e.g. tests/test_models.py::test_discriminated_unions_invalid_data_uses_cache) will fail. Either the attribute assignment needs to be restored or the rest of the code must be updated to read metadata from the Annotated type instead.

Useful? React with 👍 / 👎.

@Natim Natim mentioned this pull request Oct 28, 2025
@1155159410
Copy link

Thanks for this PR. I think it’s quite urgent since the current OpenAI API isn’t working on Python 3.14 because of this issue.

@RobertCraigie
Copy link
Collaborator

Thanks for the PR but this isn't the correct fix, the places that read the __discriminator__ property need to be updated as well

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.

AttributeError typing.Union object has no attribute __discriminator__ and not __dict__ for setting new attributes

3 participants