@@ -49,18 +49,20 @@ def init_and_validate(file, artifact_model, expected_digests):
4949 size = file .size
5050 hashers = file .hashers
5151
52+ mismatched_sha256 = None
5253 for algorithm , expected_digest in expected_digests .items ():
5354 if algorithm not in hashers :
5455 return None
5556 actual_digest = hashers [algorithm ].hexdigest ()
5657 if expected_digest != actual_digest :
57- return None
58+ # Store the actual value for later fixing if it differs from the package value
59+ mismatched_sha256 = actual_digest
5860
5961 attributes = {"size" : size , "file" : file }
6062 for algorithm in digest_fields :
6163 attributes [algorithm ] = hashers [algorithm ].hexdigest ()
6264
63- return artifact_model (** attributes )
65+ return artifact_model (** attributes ), mismatched_sha256
6466
6567
6668def extract_wheel_metadata (filename ):
@@ -104,8 +106,7 @@ def artifact_to_metadata_artifact(filename, artifact, md_digests, tmp_dir, artif
104106 temp_md .write (metadata_content )
105107 temp_md .flush ()
106108
107- metadata_artifact = init_and_validate (temp_metadata_path , artifact_model , md_digests )
108- return metadata_artifact
109+ return init_and_validate (temp_metadata_path , artifact_model , md_digests )
109110
110111
111112def create_missing_metadata_artifacts (apps , schema_editor ):
@@ -148,12 +149,16 @@ def create_missing_metadata_artifacts(apps, schema_editor):
148149 continue
149150
150151 metadata_digests = {"sha256" : package .metadata_sha256 }
151- metadata_artifact = artifact_to_metadata_artifact (
152+ metadata_artifact , mismatched_sha256 = artifact_to_metadata_artifact (
152153 filename , main_artifact , metadata_digests , temp_dir , Artifact
153154 )
154155 if not metadata_artifact :
155156 # Failed to build metadata artifact
156157 continue
158+ if mismatched_sha256 :
159+ # Fix the package if its metadata_sha256 differs from the actual value
160+ package .metadata_sha256 = mismatched_sha256
161+ package .save ()
157162
158163 contentartifact = ContentArtifact (
159164 artifact = metadata_artifact ,
0 commit comments