From 6c49b96d9da92ea2abf8b72fefd86c88969cfc93 Mon Sep 17 00:00:00 2001 From: benedikt-bartscher <31854409+benedikt-bartscher@users.noreply.github.com> Date: Wed, 21 Feb 2024 00:14:33 +0100 Subject: [PATCH] Fix SQLAlchemy list types (#2668) * fix sqlalchemy relationship list type hints * py3.8 and py3.9 compatibility Co-authored-by: Masen Furer * add missing import --------- Co-authored-by: Masen Furer --- reflex/utils/types.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/reflex/utils/types.py b/reflex/utils/types.py index abed498ee..4187d4434 100644 --- a/reflex/utils/types.py +++ b/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)