Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Fix rendering of the pulp2repositories after a failed migration.
Browse files Browse the repository at this point in the history
closes #6058
  • Loading branch information
ipanova committed Feb 4, 2020
1 parent 6e82d37 commit 5785ff6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES/6058.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix rendering of the pulp2repositories after a failed migration.
25 changes: 15 additions & 10 deletions pulp_2to3_migration/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,25 +175,27 @@ def get_pulp3_repository_href(self, obj):
"""
Get pulp3_repository_href from pulp2repo
"""
repository = obj.pulp3_repository_version.repository
return get_pulp_href(repository)
rv = obj.pulp3_repository_version
if rv:
return get_pulp_href(rv.repository)

@swagger_serializer_method(serializer_or_field=serializers.CharField)
def get_pulp3_remote_href(self, obj):
"""
Get pulp3_remote_href from pulp2repo
"""
remote = obj.pulp3_repository_remote
if not remote:
return None
return get_pulp_href(remote)
if remote:
return get_pulp_href(remote)

@swagger_serializer_method(serializer_or_field=serializers.CharField)
def get_pulp3_publication_href(self, obj):
"""
Get pulp3_publication_href from pulp3_repository_version
"""
return get_pulp_href(obj.pulp3_repository_version.publication_set.first())
rv = obj.pulp3_repository_version
if rv:
return get_pulp_href(rv.publication_set.first())

@swagger_serializer_method(
serializer_or_field=serializers.ListField(child=serializers.CharField()))
Expand All @@ -202,7 +204,10 @@ def get_pulp3_distribution_hrefs(self, obj):
Get pulp3_distribution_hrefs from pulp3_repository_version
"""
dist_list = []
result_qs = obj.pulp3_repository_version.publication_set.all()
rv = obj.pulp3_repository_version
if not rv:
return dist_list
result_qs = rv.publication_set.all()
if result_qs:
# repo_version has publication, therefore is a PublicationDistribution
for publication in result_qs:
Expand All @@ -212,11 +217,11 @@ def get_pulp3_distribution_hrefs(self, obj):
else:
# empty result_qs means that repo_version does not need publication,
# or repo_version was not published/distributed
pulp_type = obj.pulp3_repository_version.repository.pulp_type
pulp_type = rv.repository.pulp_type
distribution_type = f'{pulp_type.replace(".", "_")}distribution'
if hasattr(obj.pulp3_repository_version, distribution_type):
if hasattr(rv, distribution_type):
# repo_version is distributed directly trough RepositoryDistribution
plugin_distribution = getattr(obj.pulp3_repository_version, distribution_type)
plugin_distribution = getattr(rv, distribution_type)
dist_list = plugin_distribution.all()
else:
# repo_version was not published/distributed
Expand Down

0 comments on commit 5785ff6

Please sign in to comment.