瀏覽代碼

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 年之前
父節點
當前提交
0d8efb9b55
共有 1 個文件被更改,包括 6 次插入0 次删除
  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 sqlalchemy.ext.hybrid import hybrid_property
 from sqlalchemy.orm import DeclarativeBase, Mapped
 
 from reflex.base import Base
@@ -139,6 +140,11 @@ def get_attribute_access_type(cls: GenericType, name: str) -> GenericType | None
             if isinstance(type_, ModelField):
                 return type_.type_  # SQLAlchemy v1.4
             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):
         # Check in each arg of the annotation.
         for arg in get_args(cls):