Skip to content

Commit

Permalink
Fix import collection marks and signatures
Browse files Browse the repository at this point in the history
The import code was unable to link up a collection version with its
metadata because using multiple fields as a foreign key is not supported
by django-import-export. The only viable fallback given existing export
files is to use the upstream_id.

fixes #1836

(cherry picked from commit 4cf073b)
  • Loading branch information
mdellweg committed Aug 14, 2024
1 parent b384c8c commit 9b6bd01
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/1836.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed import failing to associate signatures and marks with their collection version.
26 changes: 26 additions & 0 deletions pulp_ansible/app/modelresource.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ def set_up_queryset(self):
"""
return CollectionVersionSignature.objects.filter(pk__in=self.repo_version.content)

def before_import_row(self, row, **kwargs):
"""
Finds and sets collection version using upstream_id.
Args:
row (tablib.Dataset row): incoming import-row representing a single content.
kwargs: args passed along from the import() call.
"""
super().before_import_row(row, **kwargs)

cv = CollectionVersion.objects.get(upstream_id=row["signed_collection"])
row["signed_collection"] = str(cv.pk)

class Meta:
model = CollectionVersionSignature
import_id_fields = ("pubkey_fingerprint", "signed_collection")
Expand All @@ -155,6 +168,19 @@ def set_up_queryset(self):
"""
return CollectionVersionMark.objects.filter(pk__in=self.repo_version.content)

def before_import_row(self, row, **kwargs):
"""
Finds and sets collection version using upstream_id.
Args:
row (tablib.Dataset row): incoming import-row representing a single content.
kwargs: args passed along from the import() call.
"""
super().before_import_row(row, **kwargs)

cv = CollectionVersion.objects.get(upstream_id=row["marked_collection"])
row["marked_collection"] = str(cv.pk)

class Meta:
model = CollectionVersionMark
import_id_fields = ("value", "marked_collection")
Expand Down

0 comments on commit 9b6bd01

Please sign in to comment.