From 2c0a704862cda1445519470476597acf56583761 Mon Sep 17 00:00:00 2001 From: Ina Panova Date: Thu, 19 Sep 2019 10:59:53 +0200 Subject: [PATCH] Fix reverse accessor clashes. closes #5479 https://pulp.plan.io/issues/5479 --- README.md | 5 ++--- pulp_2to3_migrate/app/models/content.py | 10 +++++++--- pulp_2to3_migrate/app/plugin/content.py | 2 +- pulp_2to3_migrate/app/plugin/iso/pulp3/models.py | 1 + 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 505a136e..d65a3036 100644 --- a/README.md +++ b/README.md @@ -115,8 +115,7 @@ from Pulp 2 to Pulp 3, here are some guidelines. 4. Add a Content model to pre-migrate Pulp 2 content to (subclass the provided `Pulp2to3Content` class). It has to have: - a field `type` which will correspond to the `_content_type_id` of your Content in Pulp 2. - - a ForeignKey to the `pulp_2to3_migrate.app.models.Pulp2Content` model with the `related_name` - set to `'detail_model'` (provided by `Pulp2to3Content`). + - on a Meta class a `default_related_name` set to `_detail_model` - a classmethod `pre_migrate_content_detail` (see `Pulp2to3Content` for more details) - a classmethod `migrate_content_to_pulp3` (see `Pulp2to3Content` for more details) - a method `create_pulp3_content` (see `Pulp2to3Content` for more details) @@ -129,4 +128,4 @@ class). It has to have: artifact creation. 5. Subclass the provided `Pulp2to3Importer` class and define `migrate_to_pulp3` method which - create a plugin Remote instance based on the provided pre-migrated `Pulp2Importer`. \ No newline at end of file + create a plugin Remote instance based on the provided pre-migrated `Pulp2Importer`. diff --git a/pulp_2to3_migrate/app/models/content.py b/pulp_2to3_migrate/app/models/content.py index 8105a151..b31ab9fe 100644 --- a/pulp_2to3_migrate/app/models/content.py +++ b/pulp_2to3_migrate/app/models/content.py @@ -31,13 +31,17 @@ class Meta: unique_together = ('pulp2_id', 'pulp2_content_type_id') + @property + def detail_model(self): + return getattr(self, f'{self.pulp2_content_type_id}_detail_model').get() + + class Pulp2to3Content(Model): """ Pulp 2to3 detail content model to store pulp 2 content details for Pulp 3 content creation. """ - pulp2content = models.ForeignKey(Pulp2Content, - related_name='detail_model', - on_delete=models.CASCADE) + pulp2content = models.ForeignKey(Pulp2Content, on_delete=models.CASCADE) + type = '' class Meta: diff --git a/pulp_2to3_migrate/app/plugin/content.py b/pulp_2to3_migrate/app/plugin/content.py index bdeccece..e10d8cd6 100644 --- a/pulp_2to3_migrate/app/plugin/content.py +++ b/pulp_2to3_migrate/app/plugin/content.py @@ -170,7 +170,7 @@ async def migrate_to_pulp3(self, batch, pb=None): batch: A batch of Pulp2Content objects to migrate to Pulp 3 """ for pulp2content in batch: - pulp_2to3_detail_content = pulp2content.detail_model.get() + pulp_2to3_detail_content = pulp2content.detail_model pulp3content = pulp_2to3_detail_content.create_pulp3_content() future_relations = {'pulp2content': pulp2content} diff --git a/pulp_2to3_migrate/app/plugin/iso/pulp3/models.py b/pulp_2to3_migrate/app/plugin/iso/pulp3/models.py index db6cd6ff..dc19db4c 100644 --- a/pulp_2to3_migrate/app/plugin/iso/pulp3/models.py +++ b/pulp_2to3_migrate/app/plugin/iso/pulp3/models.py @@ -24,6 +24,7 @@ class Pulp2ISO(Pulp2to3Content): class Meta: unique_together = ('name', 'checksum', 'size', 'pulp2content') + default_related_name = 'iso_detail_model' @property def expected_digests(self):