Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
raagin committed May 1, 2023
1 parent d31733b commit 31f4203
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions sortedm2m/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get_prefetch_queryset(self, instances, queryset=None):
def set(self, objs, *, clear=False, through_defaults=None):
# Force evaluation of `objs` in case it's a queryset whose value
# could be affected by `manager.clear()`. Refs #19816.
objs = tuple(objs)
# objs = tuple(objs)

db = router.db_for_write(self.through, instance=self.instance)
with transaction.atomic(using=db, savepoint=False):
Expand All @@ -58,7 +58,11 @@ def set(self, objs, *, clear=False, through_defaults=None):
self.target_field.target_field.attname, flat=True
)
)
if old_ids != [obj.pk for obj in objs] or clear:
try:
new_ids = [obj.pk for obj in objs]
except AttributeError:
new_ids = objs
if old_ids != new_ids or clear:
self.clear()
self.add(*objs, through_defaults=through_defaults)

Expand Down

0 comments on commit 31f4203

Please sign in to comment.