From 14fe4837a83d9a5ac27a5760836fe14baee027ed Mon Sep 17 00:00:00 2001 From: Fabricio Aguiar Date: Tue, 8 Oct 2019 14:26:47 -0300 Subject: [PATCH] Renaming _type to pulp_type closes #5454 https://pulp.plan.io/issues/5454 Required PR: https://github.com/pulp/pulp_file/pull/284 Required PR: https://github.com/pulp/pulpcore-plugin/pull/137 Required PR: https://github.com/PulpQE/pulp-smash/pull/1220 Required PR: https://github.com/pulp/pulp-certguard/pull/31 --- CHANGES/5454.removal | 1 + ...009_pulp_fields.py => 0010_pulp_fields.py} | 37 ++++++++++++++++++- pulpcore/app/models/base.py | 18 ++++----- pulpcore/app/models/repository.py | 8 ++-- pulpcore/app/serializers/repository.py | 6 +-- pulpcore/app/tasks/orphan.py | 2 +- 6 files changed, 54 insertions(+), 18 deletions(-) create mode 100644 CHANGES/5454.removal rename pulpcore/app/migrations/{0009_pulp_fields.py => 0010_pulp_fields.py} (94%) diff --git a/CHANGES/5454.removal b/CHANGES/5454.removal new file mode 100644 index 0000000000..24c4e6151b --- /dev/null +++ b/CHANGES/5454.removal @@ -0,0 +1 @@ +Change `_type` to `pulp_type` diff --git a/pulpcore/app/migrations/0009_pulp_fields.py b/pulpcore/app/migrations/0010_pulp_fields.py similarity index 94% rename from pulpcore/app/migrations/0009_pulp_fields.py rename to pulpcore/app/migrations/0010_pulp_fields.py index 8db96e139c..df93b17b91 100644 --- a/pulpcore/app/migrations/0009_pulp_fields.py +++ b/pulpcore/app/migrations/0010_pulp_fields.py @@ -8,7 +8,7 @@ class Migration(migrations.Migration): dependencies = [ - ('core', '0008_published_metadata_as_content'), + ('core', '0009_remove_task_non_fatal_errors'), ] operations = [ @@ -42,6 +42,11 @@ class Migration(migrations.Migration): old_name='_last_updated', new_name='pulp_last_updated', ), + migrations.RenameField( + model_name='basedistribution', + old_name='_type', + new_name='pulp_type', + ), migrations.RenameField( model_name='content', old_name='_created', @@ -57,6 +62,11 @@ class Migration(migrations.Migration): old_name='_last_updated', new_name='pulp_last_updated', ), + migrations.RenameField( + model_name='content', + old_name='_type', + new_name='pulp_type', + ), migrations.RenameField( model_name='contentappstatus', old_name='_created', @@ -102,6 +112,11 @@ class Migration(migrations.Migration): old_name='_last_updated', new_name='pulp_last_updated', ), + migrations.RenameField( + model_name='contentguard', + old_name='_type', + new_name='pulp_type', + ), migrations.RenameField( model_name='createdresource', old_name='_created', @@ -132,6 +147,11 @@ class Migration(migrations.Migration): old_name='_last_updated', new_name='pulp_last_updated', ), + migrations.RenameField( + model_name='exporter', + old_name='_type', + new_name='pulp_type', + ), migrations.RenameField( model_name='progressreport', old_name='_created', @@ -162,6 +182,11 @@ class Migration(migrations.Migration): old_name='_last_updated', new_name='pulp_last_updated', ), + migrations.RenameField( + model_name='publication', + old_name='_type', + new_name='pulp_type', + ), migrations.RenameField( model_name='publishedartifact', old_name='_created', @@ -192,6 +217,11 @@ class Migration(migrations.Migration): old_name='_last_updated', new_name='pulp_last_updated', ), + migrations.RenameField( + model_name='publisher', + old_name='_type', + new_name='pulp_type', + ), migrations.RenameField( model_name='remote', old_name='_created', @@ -207,6 +237,11 @@ class Migration(migrations.Migration): old_name='_last_updated', new_name='pulp_last_updated', ), + migrations.RenameField( + model_name='remote', + old_name='_type', + new_name='pulp_type', + ), migrations.RenameField( model_name='remoteartifact', old_name='_created', diff --git a/pulpcore/app/models/base.py b/pulpcore/app/models/base.py index c300508167..bb937f3280 100644 --- a/pulpcore/app/models/base.py +++ b/pulpcore/app/models/base.py @@ -62,12 +62,12 @@ class MasterModel(Model, metaclass=MasterModelMeta): Attributes: - TYPE (str): Default constant value saved into the ``_type`` + TYPE (str): Default constant value saved into the ``pulp_type`` field of Model instances Fields: - _type: The user-facing string identifying the detail type of this model + pulp_type: The user-facing string identifying the detail type of this model Warning: Subclasses of this class rely on there being no other parent/child Model @@ -83,14 +83,14 @@ class MasterModel(Model, metaclass=MasterModelMeta): # It can also be used for filtering across a relation where a model is related to a Master # model. Set this to something reasonable in Master and Detail model classes, e.g. when # create a master model, like "Remote", its TYPE value could be "remote". Then, when - # creating a Remote Detail class like PackageRemote, its _type value could be "package", + # creating a Remote Detail class like PackageRemote, its pulp_type value could be "package", # not "package_remote", since "package_remote" would be redundant in the context of # a remote Master model. TYPE = None # This field must have a value when models are saved, and defaults to the value of # the TYPE attribute on the Model being saved (seen above). - _type = models.TextField(null=False, default=None) + pulp_type = models.TextField(null=False, default=None) class Meta: abstract = True @@ -98,12 +98,12 @@ class Meta: def save(self, *args, **kwargs): # instances of "detail" models that subclass MasterModel are exposed # on instances of MasterModel by the string stored in that model's TYPE attr. - # Storing this _type in a column on the MasterModel next to makes it trivial + # Storing this pulp_type in a column on the MasterModel next to makes it trivial # to filter for specific detail model types across master's relations. # Prepend the TYPE defined on a detail model with a django app label. # If a plugin sets the type field themselves, it's used as-is. - if not self._type: - self._type = '{app_label}.{type}'.format(app_label=self._meta.app_label, + if not self.pulp_type: + self.pulp_type = '{app_label}.{type}'.format(app_label=self._meta.app_label, type=self.TYPE) return super().save(*args, **kwargs) @@ -147,9 +147,9 @@ def __str__(self): return super().__str__() try: - return '<{} (_type={}): {}>'.format(self._meta.object_name, cast.TYPE, cast.name) + return '<{} (pulp_type={}): {}>'.format(self._meta.object_name, cast.TYPE, cast.name) except AttributeError: - return '<{} (_type={}): pk={}>'.format(self._meta.object_name, cast.TYPE, cast.pk) + return '<{} (pulp_type={}): pk={}>'.format(self._meta.object_name, cast.TYPE, cast.pk) # Add properties to model _meta info to support master/detail models diff --git a/pulpcore/app/models/repository.py b/pulpcore/app/models/repository.py index 02804f3a1a..b1efa48b5b 100644 --- a/pulpcore/app/models/repository.py +++ b/pulpcore/app/models/repository.py @@ -495,10 +495,10 @@ def compute_counts(self): qs = self.content elif value == RepositoryVersionContentDetails.REMOVED: qs = self.removed() - annotated = qs.values('_type').annotate(count=models.Count('_type')) + annotated = qs.values('pulp_type').annotate(count=models.Count('pulp_type')) for item in annotated: count_obj = RepositoryVersionContentDetails( - content_type=item['_type'], + content_type=item['pulp_type'], repository_version=self, count=item['count'], count_type=value, @@ -561,9 +561,9 @@ def content_href(self): Args: obj (pulpcore.app.models.RepositoryVersion): The RepositoryVersion being serialized. Returns: - dict: {<_type>: } + dict: {: } """ - ctype_model = Content.objects.filter(_type=self.content_type).first().cast().__class__ + ctype_model = Content.objects.filter(pulp_type=self.content_type).first().cast().__class__ ctype_view = get_view_name_for_model(ctype_model, 'list') try: ctype_url = reverse(ctype_view) diff --git a/pulpcore/app/serializers/repository.py b/pulpcore/app/serializers/repository.py index e36d1f9147..a6501a2cca 100644 --- a/pulpcore/app/serializers/repository.py +++ b/pulpcore/app/serializers/repository.py @@ -210,9 +210,9 @@ def to_representation(self, obj): dict: The dictionary has the following format.:: { - 'added': {<_type>: {'count': , 'href': }, - 'removed': {<_type>: {'count': , 'href': }, - 'present': {<_type>: {'count': , 'href': }, + 'added': {: {'count': , 'href': }, + 'removed': {: {'count': , 'href': }, + 'present': {: {'count': , 'href': }, } """ diff --git a/pulpcore/app/tasks/orphan.py b/pulpcore/app/tasks/orphan.py index 9adbc3540a..f4f657c48d 100644 --- a/pulpcore/app/tasks/orphan.py +++ b/pulpcore/app/tasks/orphan.py @@ -11,7 +11,7 @@ def orphan_cleanup(): # Content cleanup content = Content.objects.exclude(pk__in=RepositoryContent.objects.values_list('content_id', flat=True)) - content = content.exclude(_type='core.{}'.format(PublishedMetadata.TYPE)) + content = content.exclude(pulp_type='core.{}'.format(PublishedMetadata.TYPE)) progress_bar = ProgressReport(message='Clean up orphan Content', total=content.count(), code='clean-up.content', done=0, state='running') progress_bar.save()