From 4cf073bbecb219f2543c14a2bed2bf3e4d6156c8 Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Tue, 7 May 2024 16:12:50 +0200 Subject: [PATCH] Fix import collection marks and signatures 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 --- CHANGES/1836.bugfix | 1 + pulp_ansible/app/modelresource.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 CHANGES/1836.bugfix diff --git a/CHANGES/1836.bugfix b/CHANGES/1836.bugfix new file mode 100644 index 000000000..519712fe2 --- /dev/null +++ b/CHANGES/1836.bugfix @@ -0,0 +1 @@ +Fixed import failing to associate signatures and marks with their collection version. diff --git a/pulp_ansible/app/modelresource.py b/pulp_ansible/app/modelresource.py index f82d671e6..06fd51319 100644 --- a/pulp_ansible/app/modelresource.py +++ b/pulp_ansible/app/modelresource.py @@ -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") @@ -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")