-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Teach merge_advisory() to use its own copies of relevant UpdateCollec…
…tions. Added migration to clean up and data that is already in this broken state. fixes #7291 [nocoverage]
- Loading branch information
Showing
3 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Prevented advisory-merge from 'reusing' UpdateCollections from the merging advisories. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
pulp_rpm/app/migrations/0017_merge_advisory_collections.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from django.db import ( | ||
migrations, | ||
models, | ||
) | ||
|
||
|
||
def do_clone(apps, advisory, in_collection): | ||
# We're cloning collection - find its updatecollectionpackages | ||
uc_packages = in_collection.packages.all() | ||
# break the advisory/collection link | ||
in_collection.update_record.remove(advisory) | ||
# create a new copy of the collection and link it to the advisory | ||
new_collection = in_collection | ||
new_collection.pk = None | ||
new_collection.save() | ||
# need to have an id before we can build the m2m relation | ||
new_collection.update_record.add(advisory) | ||
new_collection.save() | ||
new_packages = [] | ||
for a_package in uc_packages.iterator(): | ||
# create copies of the package list and link to new collection | ||
a_package.pk = None | ||
a_package.update_collection = new_collection | ||
new_packages.append(a_package) | ||
UpdateCollectionPackage = apps.get_model("rpm", "UpdateCollectionPackage") | ||
UpdateCollectionPackage.objects.bulk_create(new_packages) | ||
|
||
|
||
def clone_reused_update_collections(apps, schema): | ||
# Find UpdateCollections that point to multiple UpdateRecords | ||
# For all but the first one, create a clone | ||
UpdateCollection = apps.get_model("rpm", "UpdateCollection") | ||
collections = UpdateCollection.objects.annotate( | ||
num_advisories=models.Count('update_record')).filter( | ||
num_advisories__gte=2).all().iterator() | ||
for collection in collections: | ||
# Look at all the advisories this collection is associated with | ||
advisories = collection.update_record.all() | ||
# Skip the first adviroy found; for any that remain, disconnect and clone | ||
for advisory in advisories[1:]: | ||
do_clone(apps, advisory, collection) | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('rpm', '0016_dist_tree_nofk'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(clone_reused_update_collections), | ||
] |