Skip to content

Commit

Permalink
Made another migration more robust when there are "broken" modulemds.
Browse files Browse the repository at this point in the history
fixes #3196.

(cherry picked from commit 2d7beda)
  • Loading branch information
ggainey committed Jul 24, 2023
1 parent f14c9da commit a1ea6f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGES/3196.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Made 0049 migration more robust in the face of unexpected data.
27 changes: 14 additions & 13 deletions pulp_rpm/app/migrations/0049_profiles_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ def fixup_modulemd_profiles(apps, schema_editor):

for mmd in Modulemd.objects.all().iterator():
modulemd = yaml.safe_load(mmd.snippet)
unprocessed_profiles = modulemd["data"].get("profiles", {})
profiles = {}
if unprocessed_profiles:
for name, data in unprocessed_profiles.items():
rpms = data.get("rpms")
if rpms:
profiles[name] = rpms
mmd.profiles = profiles
modules_to_update.append(mmd)

if len(modules_to_update) >= 100:
Modulemd.objects.bulk_update(modules_to_update, ["profiles"])
modules_to_update.clear()
if modulemd:
unprocessed_profiles = modulemd["data"].get("profiles", {})
profiles = {}
if unprocessed_profiles:
for name, data in unprocessed_profiles.items():
rpms = data.get("rpms")
if rpms:
profiles[name] = rpms
mmd.profiles = profiles
modules_to_update.append(mmd)

if len(modules_to_update) >= 100:
Modulemd.objects.bulk_update(modules_to_update, ["profiles"])
modules_to_update.clear()

Modulemd.objects.bulk_update(modules_to_update, ["profiles"])

Expand Down

0 comments on commit a1ea6f9

Please sign in to comment.