Forráskód Böngészése

parse return type annotations of sqlalchemy hybrid properties (#2422)

* parse return type annotations of sqlylchemy hybrid properties

* use get_type_hints instead of __annotations__
benedikt-bartscher 1 éve
szülő
commit
0d8efb9b55
1 módosított fájl, 6 hozzáadás és 0 törlés
  1. 6 0
      reflex/utils/types.py

+ 6 - 0
reflex/utils/types.py

@@ -19,6 +19,7 @@ from typing import (
 )
 )
 
 
 from pydantic.fields import ModelField
 from pydantic.fields import ModelField
+from sqlalchemy.ext.hybrid import hybrid_property
 from sqlalchemy.orm import DeclarativeBase, Mapped
 from sqlalchemy.orm import DeclarativeBase, Mapped
 
 
 from reflex.base import Base
 from reflex.base import Base
@@ -139,6 +140,11 @@ def get_attribute_access_type(cls: GenericType, name: str) -> GenericType | None
             if isinstance(type_, ModelField):
             if isinstance(type_, ModelField):
                 return type_.type_  # SQLAlchemy v1.4
                 return type_.type_  # SQLAlchemy v1.4
             return type_
             return type_
+        if name in cls.__dict__:
+            value = cls.__dict__[name]
+            if isinstance(value, hybrid_property):
+                hints = get_type_hints(value.fget)
+                return hints.get("return", None)
     elif is_union(cls):
     elif is_union(cls):
         # Check in each arg of the annotation.
         # Check in each arg of the annotation.
         for arg in get_args(cls):
         for arg in get_args(cls):