Skip to content

Optional Union fix#1690

Merged
vitalik merged 1 commit intomasterfrom
uniont-type
Mar 6, 2026
Merged

Optional Union fix#1690
vitalik merged 1 commit intomasterfrom
uniont-type

Conversation

@vitalik
Copy link
Owner

@vitalik vitalik commented Mar 5, 2026

  • Fix [BUG] For optional fields using Union (type1 | type2), it raises exception. #1634: Model | None (union type) in Query parameters crashes with AttributeError: 'types.UnionType' object has no attribute 'model_fields'
  • Add private _unwrap_union_model() helper to extract the pydantic model from union types before accessing .model_fields
  • Fix both crash sites: _model_flatten_map and detect_collection_fields

Based on

PR #1647 by @Nuung minimized structural changes to existing functions.

fixes #1634

Co-Authored-By: Nuung <qlgks1@naver.com>
Copy link
Contributor

@Nuung Nuung left a comment

Choose a reason for hiding this comment

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

I fully agree. It looks much cleaner. thank you!

@vitalik vitalik merged commit 9d9bd05 into master Mar 6, 2026
106 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.

[BUG] For optional fields using Union (type1 | type2), it raises exception.

2 participants