fix: suppress on_create/on_delete for objects created and deleted within the same transaction (#166)

This commit is contained in:
d3vyce
2026-03-23 18:51:28 +01:00
committed by GitHub
parent 100e1c1aa9
commit bcb5b0bfda
2 changed files with 154 additions and 5 deletions

View File

@@ -186,6 +186,15 @@ def _after_commit(session: Any) -> None:
_SESSION_UPDATES, {}
)
if creates and deletes:
transient_ids = {id(o) for o in creates} & {id(o) for o in deletes}
if transient_ids:
creates = [o for o in creates if id(o) not in transient_ids]
deletes = [o for o in deletes if id(o) not in transient_ids]
field_changes = {
k: v for k, v in field_changes.items() if k not in transient_ids
}
if not creates and not deletes and not field_changes:
return