From 3ab3d0068a60f15d4931d3653a081f92cee9ce51 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Thu, 18 Jul 2024 09:59:12 -0400 Subject: [PATCH] Cast the content object to a collectionversion before manipulating and saving. fixes #1921 Signed-off-by: James Tanner --- CHANGES/1921.bugfix | 1 + pulp_ansible/app/tasks/collections.py | 8 ++++++-- pulp_ansible/tests/unit/test_tasks.py | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 CHANGES/1921.bugfix diff --git a/CHANGES/1921.bugfix b/CHANGES/1921.bugfix new file mode 100644 index 000000000..e26280d78 --- /dev/null +++ b/CHANGES/1921.bugfix @@ -0,0 +1 @@ +Cast the content object to a collectionversion before setting the rebuild metadata. diff --git a/pulp_ansible/app/tasks/collections.py b/pulp_ansible/app/tasks/collections.py index 0eaee3410..27bd74478 100644 --- a/pulp_ansible/app/tasks/collections.py +++ b/pulp_ansible/app/tasks/collections.py @@ -384,10 +384,14 @@ def rebuild_repository_collection_versions_metadata( ptotal.increment() -def _rebuild_collection_version_meta(collection_version): +def _rebuild_collection_version_meta(content_object): """Rebuild metadata for a single collection version.""" + + # Cast to get the CV + collection_version = content_object.cast() + # where is the artifact? - artifact = collection_version._artifacts.first() + artifact = content_object._artifacts.first() # call the importer to re-generate meta importer_result = process_collection( diff --git a/pulp_ansible/tests/unit/test_tasks.py b/pulp_ansible/tests/unit/test_tasks.py index 7a9d608f1..d1e7cedfb 100644 --- a/pulp_ansible/tests/unit/test_tasks.py +++ b/pulp_ansible/tests/unit/test_tasks.py @@ -101,6 +101,25 @@ def test_reimport_repository_rebuilds_name(self, mock_progress_report, mock_rebu expected_pks = sorted([str(x.pk) for x in expected_cvs]) assert call_pks == expected_pks + def test_reimport_repository_rebuilds_contents(self): + """Make sure the contents field in the CVs are rebuilt.""" + + cobject = self.repo.latest_version().content.first() + assert cobject is not None, "the repo fixture no longer has content for some unknown reason" + + # set some invalid contents for each CV in the repo ... + cv = cobject.cast() + cv.contents = ["a", "b", "c"] + cv.save() + + # call the rebuild + _rebuild_collection_version_meta(cobject) + + # after rebuild, the contents should have been changed back + cv2 = cobject.cast() + cv2.refresh_from_db() + assert cv2.contents != ["a", "b", "c"] + class TestCollectionVersionHighest(TestCase): """Test Collection Re-Import."""