Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #3200/2d7bedab backport][3.21] Made another migration more robust when there are "broken" modulemds. #3203

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading