Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed test.
  • Loading branch information
jackton1 committed Apr 23, 2021
commit 9d1dcf903ebc1b21587dfb0ae472ff0145ea3b09
5 changes: 4 additions & 1 deletion model_clone/mixins/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,10 @@ def __duplicate_m2m_fields(self, duplicate, sub_clone):
objs = through.objects.filter(**{field_name: self.pk})
for item in objs:
if hasattr(through, "make_clone"):
item.make_clone(attrs={field_name: duplicate}, sub_clone=True)
try:
item.make_clone(attrs={field_name: duplicate})
except IntegrityError:
item.make_clone(attrs={field_name: duplicate}, sub_clone=True)
else:
item.pk = None
setattr(item, field_name, duplicate)
Expand Down