浏览代码

Fix SQLAlchemy list types (#2668)

* fix sqlalchemy relationship list type hints

* py3.8 and py3.9 compatibility

Co-authored-by: Masen Furer <m_github@0x26.net>

* add missing import

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
benedikt-bartscher 1 年之前
父节点
当前提交
6c49b96d9d
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      reflex/utils/types.py

+ 6 - 1
reflex/utils/types.py

@@ -10,6 +10,7 @@ from typing import (
     Any,
     Callable,
     Iterable,
+    List,
     Literal,
     Optional,
     Type,
@@ -164,7 +165,11 @@ def get_attribute_access_type(cls: GenericType, name: str) -> GenericType | None
             prop = descriptor.property
             if not isinstance(prop, Relationship):
                 return None
-            return prop.mapper.class_
+            class_ = prop.mapper.class_
+            if prop.uselist:
+                return List[class_]
+            else:
+                return class_
     elif isinstance(cls, type) and issubclass(cls, Model):
         # Check in the annotations directly (for sqlmodel.Relationship)
         hints = get_type_hints(cls)