Skip to content

Commit

Permalink
Cast the content object to a collectionversion before manipulating an…
Browse files Browse the repository at this point in the history
…d saving.

fixes #1921

Signed-off-by: James Tanner <tanner.jc@gmail.com>
  • Loading branch information
jctanner authored and mdellweg committed Jul 18, 2024
1 parent fd93af6 commit 3ab3d00
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/1921.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cast the content object to a collectionversion before setting the rebuild metadata.
8 changes: 6 additions & 2 deletions pulp_ansible/app/tasks/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
19 changes: 19 additions & 0 deletions pulp_ansible/tests/unit/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 3ab3d00

Please sign in to comment.