Skip to content

Commit 833b946

Browse files
committed
fix(decorators): merge annotations from base classes for Tortoise compatibility
1 parent 60ed925 commit 833b946

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

fastapi_ronin/decorators.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,21 @@ def decorator(func: Callable) -> Callable:
6464
def schema(model: Type[Model], **kwargs):
6565
"""Decorator to mark a viewset method as a routable action."""
6666

67+
def _get_all_annotations(cls):
68+
annotations = {}
69+
for base in reversed(cls.__mro__):
70+
annotations.update(getattr(base, '__annotations__', {}))
71+
return annotations
72+
6773
def decorator(cls):
6874
cls.model_config['orig_model'] = model # type: ignore
6975

76+
# Explicitly merge annotations from base classes.
77+
# Tortoise reads cls.__annotations__ directly and does not account for inheritance,
78+
# so we flatten the MRO annotations into the current class to make inherited
79+
# schema fields visible to Tortoise.
80+
# tortoise/contrib/pydantic/base.py, line 29
81+
cls.__annotations__ = _get_all_annotations(cls)
7082
return cls
7183

7284
return decorator

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)