diff --git a/pulpcore/app/models/upload.py b/pulpcore/app/models/upload.py index 5e8a8981f3..90835a086a 100644 --- a/pulpcore/app/models/upload.py +++ b/pulpcore/app/models/upload.py @@ -30,11 +30,12 @@ def append(self, chunk, offset, sha256=None): offset (int): First byte position to write chunk to. """ chunk_read = chunk.read() - current_sha256 = hashlib.sha256(chunk_read).hexdigest() - if sha256 and sha256 != current_sha256: - raise serializers.ValidationError("Checksum does not match chunk upload.") + if sha256: + current_sha256 = hashlib.sha256(chunk_read).hexdigest() + if sha256 != current_sha256: + raise serializers.ValidationError("Checksum does not match chunk upload.") - upload_chunk = UploadChunk(upload=self, offset=offset, size=len(chunk)) + upload_chunk = UploadChunk(upload=self, offset=offset, size=len(chunk_read)) filename = os.path.basename(upload_chunk.storage_path("")) upload_chunk.file.save(filename, ContentFile(chunk_read))