Skip to content
Merged
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/+content-href-missing-viewset.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed repository version serialization failing with `LookupError` when the version contains a content type that has no registered viewset.
4 changes: 2 additions & 2 deletions pulpcore/app/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -1579,10 +1579,10 @@ def get_content_href(self, request=None):
)
ctypes = {c.get_pulp_type(): c for c in repository_model.CONTENT_TYPES}
ctype_model = ctypes[self.content_type]
ctype_view = get_view_name_for_model(ctype_model, "list")
try:
ctype_view = get_view_name_for_model(ctype_model, "list")
ctype_url = reverse(ctype_view, request=request)
except django.urls.exceptions.NoReverseMatch:
except (LookupError, django.urls.exceptions.NoReverseMatch):
# We've hit a content type for which there is no viewset.
# There's nothing we can do here, except to skip it.
return
Expand Down
19 changes: 19 additions & 0 deletions pulpcore/tests/unit/models/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,3 +813,22 @@ def test_batch_operations_preserve_correctness(repository, db):
assert rvcd_qs.get(count_type=RepositoryVersionContentDetails.PRESENT).count == 40
assert rvcd_qs.filter(count_type=RepositoryVersionContentDetails.ADDED).first() is None
assert rvcd_qs.get(count_type=RepositoryVersionContentDetails.REMOVED).count == 60


def test_get_content_href_without_viewset(db, repository, monkeypatch):
"""A content type with no registered viewset yields no href instead of raising."""

def no_viewset(model_obj, view_action):
raise LookupError(f"Could not determine ViewSet base name for model {model_obj}")

monkeypatch.setattr(Repository, "CONTENT_TYPES", [Content])
monkeypatch.setattr("pulpcore.app.models.repository.get_view_name_for_model", no_viewset)
version = RepositoryVersion.objects.create(repository=repository, number=1, complete=True)
count_detail = RepositoryVersionContentDetails.objects.create(
repository_version=version,
content_type=Content.get_pulp_type(),
count_type=RepositoryVersionContentDetails.ADDED,
count=1,
)

assert count_detail.get_content_href() is None
Loading