support parsing type args of DeclarativeBase subclasses (#2348)

This commit is contained in:
benedikt-bartscher 2024-01-03 20:55:07 +01:00 committed by GitHub
parent efbf3d9243
commit 58a7e5e460
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,7 +19,7 @@ from typing import (
) )
from pydantic.fields import ModelField from pydantic.fields import ModelField
from sqlalchemy.orm import Mapped from sqlalchemy.orm import DeclarativeBase, Mapped
from reflex.base import Base from reflex.base import Base
from reflex.utils import serializers from reflex.utils import serializers
@ -128,7 +128,7 @@ def get_attribute_access_type(cls: GenericType, name: str) -> GenericType | None
# Ensure frontend uses null coalescing when accessing. # Ensure frontend uses null coalescing when accessing.
type_ = Optional[type_] type_ = Optional[type_]
return type_ return type_
elif isinstance(cls, type) and issubclass(cls, Model): elif isinstance(cls, type) and issubclass(cls, (Model, DeclarativeBase)):
# Check in the annotations directly (for sqlmodel.Relationship) # Check in the annotations directly (for sqlmodel.Relationship)
hints = get_type_hints(cls) hints = get_type_hints(cls)
if name in hints: if name in hints: