1- from contextlib import suppress
21from gettext import gettext as _
32from json .decoder import JSONDecodeError
43
@@ -34,6 +33,7 @@ class Command(BaseCommand):
3433
3534 def handle (self , * args , ** options ):
3635 manifests_updated_count = 0
36+ self ._broken_manifests = []
3737
3838 manifests_v1 = Manifest .objects .filter (
3939 Q (media_type = MEDIA_TYPE .MANIFEST_V1 ),
@@ -68,6 +68,13 @@ def handle(self, *args, **options):
6868 self .style .SUCCESS ("Successfully updated %d manifests." % manifests_updated_count )
6969 )
7070
71+ if self ._broken_manifests :
72+ self .stdout .write (
73+ self .style .WARNING ("Found %d broken manifests. PKs:" % len (self ._broken_manifests ))
74+ )
75+ for manifest in self ._broken_manifests :
76+ self .stdout .write (self .style .WARNING (" %s" % manifest .pk ))
77+
7178 if settings .CACHE_ENABLED and manifests_updated_count != 0 :
7279 base_paths = ContainerDistribution .objects .values_list ("base_path" , flat = True )
7380 if base_paths :
@@ -91,11 +98,13 @@ def update_manifests(self, manifests_qs):
9198 ]
9299
93100 for manifest in manifests_qs .iterator ():
94- # suppress non-existing/already migrated artifacts and corrupted JSON files
95- with suppress (ObjectDoesNotExist , JSONDecodeError ):
101+ try :
96102 needs_update = self .init_manifest (manifest )
97- if needs_update :
98- manifests_to_update .append (manifest )
103+ except (ObjectDoesNotExist , JSONDecodeError ):
104+ self ._broken_manifests .append (manifest )
105+ continue
106+ if needs_update :
107+ manifests_to_update .append (manifest )
99108
100109 if len (manifests_to_update ) > 1000 :
101110 manifests_qs .model .objects .bulk_update (
0 commit comments