From fa1bd58a4ac11d38b87df25048fb8caf6c5735fa Mon Sep 17 00:00:00 2001 From: Dustin Ingram Date: Fri, 30 Aug 2024 18:30:31 +0000 Subject: [PATCH] Add the Attestation object to the session --- warehouse/attestations/services.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/warehouse/attestations/services.py b/warehouse/attestations/services.py index 1c2098363052..31dc8c1cbf60 100644 --- a/warehouse/attestations/services.py +++ b/warehouse/attestations/services.py @@ -140,15 +140,15 @@ def generate_provenance( provenance = Provenance(attestation_bundles=[attestation_bundle]) for attestation in attestations: - database_attestation = DatabaseAttestation( - file=file, - attestation_file_blake2_digest=hashlib.blake2b( - attestation.model_dump_json().encode("utf-8") - ).hexdigest(), + self.db.add( + DatabaseAttestation( + file=file, + attestation_file_blake2_digest=hashlib.blake2b( + attestation.model_dump_json().encode("utf-8") + ).hexdigest(), + ) ) - file.attestations.append(database_attestation) - return provenance def get_provenance_digest(self, file: File) -> str | None: @@ -241,6 +241,7 @@ def parse_attestations( def generate_provenance( self, request: Request, file: File, attestations: list[Attestation] ) -> Provenance | None: + # Generate the provenance object. provenance = self._build_provenance_object(request.oidc_publisher, attestations) @@ -276,6 +277,7 @@ def _persist_attestations( database_attestation = DatabaseAttestation( file=file, attestation_file_blake2_digest=attestation_digest ) + self.db.add(database_attestation) self.storage.store( database_attestation.attestation_path, @@ -283,8 +285,6 @@ def _persist_attestations( meta=None, ) - file.attestations.append(database_attestation) - def _build_provenance_object( self, oidc_publisher: OIDCPublisher, attestations: list[Attestation] ) -> Provenance | None: