diff --git a/CHANGES/5149.bugfix b/CHANGES/5149.bugfix new file mode 100644 index 00000000000..ae577e0d070 --- /dev/null +++ b/CHANGES/5149.bugfix @@ -0,0 +1,2 @@ +Fixed bug where Last-Modified header of packages in django-storages was being updated on duplicate +uploads. \ No newline at end of file diff --git a/pulpcore/plugin/viewsets/content.py b/pulpcore/plugin/viewsets/content.py index 961bf27e15a..6390b7c0788 100644 --- a/pulpcore/plugin/viewsets/content.py +++ b/pulpcore/plugin/viewsets/content.py @@ -133,18 +133,20 @@ def init_content_data(self, serializer, request): # in the upload code path make sure, the artifact exists, and the 'file' # parameter is replaced by 'artifact' artifact = Artifact.init_and_validate(task_payload.pop("file")) + # if artifact already exists, let's use it try: - artifact.save() - except IntegrityError: - # if artifact already exists, let's use it + artifact = Artifact.objects.get( + sha256=artifact.sha256, pulp_domain=request.pulp_domain + ) + artifact.touch() + except (Artifact.DoesNotExist, DatabaseError): try: + artifact.save() + except IntegrityError: artifact = Artifact.objects.get( sha256=artifact.sha256, pulp_domain=request.pulp_domain ) artifact.touch() - except (Artifact.DoesNotExist, DatabaseError): - # the artifact has since been removed from when we first attempted to save it - artifact.save() task_payload["artifact"] = ArtifactSerializer( artifact, context={"request": request}