Skip to content

Commit

Permalink
Merge pull request #41 from django-oscar/duplicate-instances-support
Browse files Browse the repository at this point in the history
[FEAT] Assign pk to duplicate instances
  • Loading branch information
specialunderwear authored Sep 18, 2024
2 parents 4dbeb13 + d874ab8 commit 1bc458e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions oscar_odin/mappings/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ def assign_pk_to_duplicate_instances(self, instances, validated_instances):
e.g, instances contain two product classes, one with pk=2 and one with pk=None,
both have same slug. This method will assign both pk=2 to both instances.
"""
if not instances:
return
identifiers = self.identifier_mapping.get(instances[0].__class__)
pk_identity_map = {
self.get_identity(instance, identifiers): instance.pk
Expand Down Expand Up @@ -248,6 +250,9 @@ def bulk_update_or_create_instances(self, instances):

validated_create_instances = self.validate_instances(instances_to_create)
self.Model.objects.bulk_create(validated_create_instances)
self.assign_pk_to_duplicate_instances(
instances_to_create, validated_create_instances
)
for instance in validated_create_instances:
if instance.pk is None:
raise OscarOdinException(
Expand Down

0 comments on commit 1bc458e

Please sign in to comment.