fix handle_m2m_changed

This commit is contained in:
Laura Klünder 2024-12-13 01:11:53 +00:00
parent 7ba2f60ce3
commit 576be08232
2 changed files with 5 additions and 1 deletions

View file

@ -247,6 +247,9 @@ class DatabaseOperationCollection(BaseSchema):
def append(self, item: DatabaseOperation):
self.operations.append(item)
def __getitem__(self, item):
return self.operations[item]
def prefetch(self) -> "PrefetchedDatabaseOperationCollection":
return PrefetchedDatabaseOperationCollection(operations=self, instances=self.prev.get_instances())

View file

@ -148,7 +148,8 @@ class DatabaseOverlayManager:
if self.operations:
last_change = self.operations[-1]
if isinstance(last_change, UpdateManyToManyOperation) and last_change == ref and last_change == field.name:
if (isinstance(last_change, UpdateManyToManyOperation)
and last_change.obj == ref and last_change == field.name):
if action == "post_add":
last_change.add_values.update(pk_set)
last_change.remove_values.difference_update(pk_set)