1- from contextlib import suppress
1+ from collections import defaultdict
22from gettext import gettext as _
33from json .decoder import JSONDecodeError
44
88from django .db .models import Q
99
1010from pulpcore .plugin .cache import SyncContentCache
11+ from pulpcore .plugin .util import get_url
1112
1213from pulp_container .app .models import ContainerDistribution , Manifest
1314from pulp_container .app .utils import get_content_data
@@ -34,6 +35,7 @@ class Command(BaseCommand):
3435
3536 def handle (self , * args , ** options ):
3637 manifests_updated_count = 0
38+ self ._broken_manifests = []
3739
3840 manifests_v1 = Manifest .objects .filter (
3941 Q (media_type = MEDIA_TYPE .MANIFEST_V1 ),
@@ -68,6 +70,23 @@ def handle(self, *args, **options):
6870 self .style .SUCCESS ("Successfully updated %d manifests." % manifests_updated_count )
6971 )
7072
73+ if self ._broken_manifests :
74+ self .stdout .write (
75+ self .style .WARNING ("Found %d broken manifests." % len (self ._broken_manifests ))
76+ )
77+ broken_by_repo = defaultdict (list )
78+ for manifest in self ._broken_manifests :
79+ repos = manifest .repositories .all ()
80+ if repos :
81+ for repo in repos :
82+ broken_by_repo [get_url (repo )].append (get_url (manifest ))
83+ else :
84+ broken_by_repo ["orphaned" ].append (get_url (manifest ))
85+ for repo_url , manifests in broken_by_repo .items ():
86+ self .stdout .write (self .style .WARNING (" %s" % repo_url ))
87+ for manifest_url in manifests :
88+ self .stdout .write (self .style .WARNING (" %s" % manifest_url ))
89+
7190 if settings .CACHE_ENABLED and manifests_updated_count != 0 :
7291 base_paths = ContainerDistribution .objects .values_list ("base_path" , flat = True )
7392 if base_paths :
@@ -91,11 +110,13 @@ def update_manifests(self, manifests_qs):
91110 ]
92111
93112 for manifest in manifests_qs .iterator ():
94- # suppress non-existing/already migrated artifacts and corrupted JSON files
95- with suppress (ObjectDoesNotExist , JSONDecodeError ):
113+ try :
96114 needs_update = self .init_manifest (manifest )
97- if needs_update :
98- manifests_to_update .append (manifest )
115+ except (ObjectDoesNotExist , JSONDecodeError ):
116+ self ._broken_manifests .append (manifest )
117+ continue
118+ if needs_update :
119+ manifests_to_update .append (manifest )
99120
100121 if len (manifests_to_update ) > 1000 :
101122 manifests_qs .model .objects .bulk_update (
0 commit comments