Skip to content

Fix: preserve relationship annotations during class creation#1857

Open
aliyevr889 wants to merge 2 commits intofastapi:mainfrom
aliyevr889:fix/preserve-relationship-annotations
Open

Fix: preserve relationship annotations during class creation#1857
aliyevr889 wants to merge 2 commits intofastapi:mainfrom
aliyevr889:fix/preserve-relationship-annotations

Conversation

@aliyevr889
Copy link
Copy Markdown

Fixes #530. This PR ensures that Relationship annotations are preserved in annotations during the class creation phase, allowing init_subclass and other initialization hooks to inspect them.
The fix preserves all original annotations in the metadata passed to the base metaclass, and then cleans up any Pydantic fields automatically created for relationships to avoid validation overhead.

…ation preservation

Cover three scenarios:
1. Relationship annotations visible in __init_subclass__ hooks
2. Relationship fields excluded from Pydantic model_fields
3. End-to-end relationship functionality still works after the fix

Fixes fastapi#530
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.

Relationship type annotations disappear after class definition is evaluated

2 participants