Skip to content

Commit ca1d33a

Browse files
authored
Apply attribute access rules for Model or SQLModel (#5875)
Fix #5872
1 parent af33d11 commit ca1d33a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

reflex/utils/types.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,13 @@ def get_attribute_access_type(cls: GenericType, name: str) -> GenericType | None
443443

444444
from reflex.model import Model
445445

446+
if find_spec("sqlmodel"):
447+
from sqlmodel import SQLModel
448+
449+
sqlmodel_types = (Model, SQLModel)
450+
else:
451+
sqlmodel_types = (Model,)
452+
446453
if isinstance(cls, type) and issubclass(cls, DeclarativeBase):
447454
insp = sqlalchemy.inspect(cls)
448455
if name in insp.columns:
@@ -486,7 +493,7 @@ def get_attribute_access_type(cls: GenericType, name: str) -> GenericType | None
486493
elif (
487494
isinstance(cls, type)
488495
and not is_generic_alias(cls)
489-
and issubclass(cls, Model)
496+
and issubclass(cls, sqlmodel_types)
490497
):
491498
# Check in the annotations directly (for sqlmodel.Relationship)
492499
hints = get_type_hints(cls) # pyright: ignore [reportArgumentType]

0 commit comments

Comments
 (0)