Skip to content

Commit e58987d

Browse files
committed
Fixes to sync()
* Save/sync executor attempted to commit changes to pydantic objects even when there was an exception inside its context manager * Sync was writing changes to pydantic objects while the transaction was still open * Fix sync() to update single links properly and handle the case when a linked object is replaced with a different one * Drop BlockingClient.__save_debug__ method, it's quite outdated and must be broken
1 parent 1147606 commit e58987d

File tree

5 files changed

+227
-246
lines changed

5 files changed

+227
-246
lines changed

gel/_internal/_qbmodel/_abstract/_descriptors.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -750,11 +750,13 @@ def reconcile_link(
750750
existing_objects: dict[uuid.UUID, _MT_co | Iterable[_MT_co]],
751751
new_objects: dict[uuid.UUID, _MT_co],
752752
) -> _MT_co:
753-
if existing is not None:
754-
return existing
755-
756753
obj_id: uuid.UUID = ll_getattr(refetched, "id")
757754

755+
if existing is not None:
756+
existing_id = ll_getattr(existing, "id")
757+
if existing_id == obj_id:
758+
return existing
759+
758760
if (link_to := existing_objects.get(obj_id)) is not None:
759761
if isinstance(link_to, AbstractGelModel):
760762
return link_to
@@ -771,15 +773,18 @@ def reconcile_proxy_link(
771773
existing_objects: dict[uuid.UUID, _MT_co | Iterable[_MT_co]],
772774
new_objects: dict[uuid.UUID, _MT_co],
773775
) -> AbstractGelProxyModel[_MT_co, _LM_co]:
776+
obj_id: uuid.UUID = ll_getattr(refetched.without_linkprops(), "id")
777+
774778
if existing is not None:
775-
# `refetched` will have newly refetched __linkprops__,
776-
# so copy them
777-
existing.__gel_replace_linkprops__(
778-
copy_or_ref_lprops(refetched.__linkprops__)
779-
)
780-
return existing
779+
existing_id: uuid.UUID = ll_getattr(existing.without_linkprops(), "id")
781780

782-
obj_id: uuid.UUID = ll_getattr(refetched.without_linkprops(), "id")
781+
if existing_id == obj_id:
782+
# `refetched` will have newly refetched __linkprops__,
783+
# so copy them
784+
existing.__gel_replace_linkprops__(
785+
copy_or_ref_lprops(refetched.__linkprops__)
786+
)
787+
return existing
783788

784789
if (_link_to := existing_objects.get(obj_id)) is not None:
785790
if isinstance(_link_to, AbstractGelModel):

0 commit comments

Comments
 (0)