Skip to content

Commit 6216409

Browse files
authored
♻ Refactor internal statements to simplify code (#53)
1 parent 6fe256e commit 6216409

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

sqlmodel/main.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,8 @@ def __setattr__(self, name: str, value: Any) -> None:
519519
return
520520
else:
521521
# Set in SQLAlchemy, before Pydantic to trigger events and updates
522-
if getattr(self.__config__, "table", False):
523-
if is_instrumented(self, name):
524-
set_attribute(self, name, value)
522+
if getattr(self.__config__, "table", False) and is_instrumented(self, name):
523+
set_attribute(self, name, value)
525524
# Set in Pydantic model to trigger possible validation changes, only for
526525
# non relationship values
527526
if name not in self.__sqlmodel_relationships__:
@@ -611,7 +610,7 @@ def _calculate_keys(
611610
exclude_unset: bool,
612611
update: Optional[Dict[str, Any]] = None,
613612
) -> Optional[AbstractSet[str]]:
614-
if include is None and exclude is None and exclude_unset is False:
613+
if include is None and exclude is None and not exclude_unset:
615614
# Original in Pydantic:
616615
# return None
617616
# Updated to not return SQLAlchemy attributes
@@ -629,7 +628,6 @@ def _calculate_keys(
629628
# Do not include relationships as that would easily lead to infinite
630629
# recursion, or traversing the whole database
631630
keys = self.__fields__.keys() # | self.__sqlmodel_relationships__.keys()
632-
633631
if include is not None:
634632
keys &= include.keys()
635633

0 commit comments

Comments
 (0)