Skip to content

Commit

Permalink
addressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
simon committed Sep 28, 2024
1 parent 6f55a91 commit 69c8b76
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 2 additions & 3 deletions reflex/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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__()
Expand Down
12 changes: 7 additions & 5 deletions reflex/utils/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 69c8b76

Please sign in to comment.