Skip to content

explicitly handle discriminator + oneOf for pydantic Unions#1202

Open
cosmicBboy wants to merge 2 commits into
mainfrom
nielsb/pydantic-fix
Open

explicitly handle discriminator + oneOf for pydantic Unions#1202
cosmicBboy wants to merge 2 commits into
mainfrom
nielsb/pydantic-fix

Conversation

@cosmicBboy

Copy link
Copy Markdown
Contributor

This pull request refactors the logic for generating attribute lists from dataclass JSON schemas, improving the handling of $ref references and discriminated unions in Pydantic-generated schemas. It also updates dependency recency exclusion for the flyte package.

Schema processing improvements

  • Refactored the order of handling for $ref references and discriminated unions in generate_attribute_list_from_dataclass_json_mixin, ensuring that non-dict property values and discriminated unions with both discriminator and oneOf are handled before $ref logic. This makes the type inference more robust and fixes edge cases with Pydantic v2 schemas.
  • Moved the $ref handling block to after the checks for non-dict property values and discriminated unions, restoring and improving the previous logic for nested models and custom types.

Dependency management

  • Added flyte = "0 days" to the [tool.uv.exclude-newer-package] section in pyproject.toml, ensuring that the latest flyte package releases are picked up immediately, similar to other Flyte-related packages.

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
@cosmicBboy cosmicBboy requested a review from AdilFayyaz June 12, 2026 17:15
@cosmicBboy

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

@cosmicBboy cosmicBboy removed the request for review from AdilFayyaz June 12, 2026 17:17

Copilot AI commented Jun 12, 2026

Copy link
Copy Markdown

@copilot resolve the merge conflicts in this pull request

Resolved the merge conflict in uv.lock. The only conflict was in the [options.exclude-newer-package] section — I kept the flyte entry from this branch and used the updated timestamps for flyteidl2 and flyte-controller-base from main.

# top-level "type"; instead it has "oneOf" with the variant schemas.
if property_val.get("oneOf"):
# Handle discriminated unions (Pydantic v2) - check for both discriminator and oneOf together
if "discriminator" in property_val and "oneOf" in property_val:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can a oneOf exist without a discriminator?

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