diff --git a/reflex/model.py b/reflex/model.py index 3abb4c3cd8..0e8d62e90d 100644 --- a/reflex/model.py +++ b/reflex/model.py @@ -22,7 +22,7 @@ from reflex.base import Base from reflex.config import get_config from reflex.utils import console -from reflex.utils.compat import sqlmodel, sa_column_id_supporter +from reflex.utils.compat import sqlmodel, sqlmodel_field_has_primary_key def get_engine(url: str | None = None) -> sqlalchemy.engine.Engine: @@ -166,10 +166,9 @@ def __init_subclass__(cls): non_default_primary_key_fields = [ field_name for field_name, field in cls.__fields__.items() - if field_name != "id" and sa_column_id_supporter(field) + if field_name != "id" and sqlmodel_field_has_primary_key(field) ] if non_default_primary_key_fields: - print(cls.__name__, non_default_primary_key_fields) cls.__fields__.pop("id", None) super().__init_subclass__() diff --git a/reflex/utils/compat.py b/reflex/utils/compat.py index 3d99ffd079..ea854078de 100644 --- a/reflex/utils/compat.py +++ b/reflex/utils/compat.py @@ -71,12 +71,14 @@ def pydantic_v1_patch(): import sqlmodel as sqlmodel -def sa_column_id_supporter(field) -> bool: - """Adds support for sa_column so we don't add id with a primary key - is defined +def sqlmodel_field_has_primary_key(field) -> bool: + """Determines if a field is a priamary - AKA simons_litttle_helper - AKA masens_litttlerrr_helperr + Args: + field: a rx.model field + + Returns: + If field is a primary key (Bool) """ if getattr(field.field_info, "primary_key", None) is True: return True