Skip to content

Commit

Permalink
Removing _type field
Browse files Browse the repository at this point in the history
  • Loading branch information
fao89 authored and daviddavis committed Oct 9, 2019
1 parent 14fe483 commit 2a62d16
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 49 deletions.
1 change: 1 addition & 0 deletions CHANGES/5550.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removing base serializer field: `_type` .
2 changes: 1 addition & 1 deletion docs/contributing/architecture/rest-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ representing the Master Model in a Master/Detail relationship, and every Seriali
Detail Models must subclass their respective Master Serializer.

Furthermore, every Serializer representing a Master Model should subclass a special Serializer
created for Master/Detail models, :class:`pulpcore.app.serializers.base.MasterModelSerializer`. This
created for Master/Detail models, :class:`pulpcore.app.serializers.base.ModelSerializer`. This
Serializer includes a definition for the `type` field present on all models inheriting from
:class:`pulpcore.app.models.MasterModel`, and also identifies the `type` field as filterable,
centralizing common behavior that we're likely to want in all Serializers representing Models
Expand Down
1 change: 0 additions & 1 deletion pulpcore/app/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
DetailIdentityField,
DetailRelatedField,
IdentityField,
MasterModelSerializer,
ModelSerializer,
NestedIdentityField,
NestedRelatedField,
Expand Down
32 changes: 0 additions & 32 deletions pulpcore/app/serializers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,38 +78,6 @@ def validate(self, data):
return data


class MasterModelSerializer(ModelSerializer):
"""
Base serializer for all Master/Detail Models.
When subclassing this, all subclasses should explicitly inherit the fields of their parent
in their Meta options class. For example:
class MasterSerializer(MasterModelSerializer):
foo = SerializerField()
class Meta:
fields = MasterModelSerializer.Meta.fields + ('foo',)
class DetailSerializer(MasterSerializer):
bar = SerializerField()
class Meta:
fields = MasterSerializer.Meta.fields + ('bar',)
This ensures that fields are represented consistently throughout the API, and Detail Model
types are cast down before representation.
Other Meta attributes, such as `filterset_fields`, should also be inherited in this way
as-needed.
"""
_type = serializers.CharField(read_only=True)

class Meta:
fields = ModelSerializer.Meta.fields + ('_type',)


class MatchingNullViewName(object):
"""Object that can be used as the default view name for detail fields
Expand Down
4 changes: 2 additions & 2 deletions pulpcore/app/serializers/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
UNIQUE_ALGORITHMS = ['sha256', 'sha384', 'sha512']


class BaseContentSerializer(base.MasterModelSerializer):
class BaseContentSerializer(base.ModelSerializer):
pulp_href = base.DetailIdentityField()

class Meta:
model = models.Content
fields = base.MasterModelSerializer.Meta.fields
fields = base.ModelSerializer.Meta.fields


class NoArtifactContentSerializer(BaseContentSerializer):
Expand Down
11 changes: 5 additions & 6 deletions pulpcore/app/serializers/publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
BaseURLField,
DetailIdentityField,
DetailRelatedField,
MasterModelSerializer,
ModelSerializer,
NestedRelatedField,
RelatedField,
validate_unknown_fields,
)


class PublicationSerializer(MasterModelSerializer):
class PublicationSerializer(ModelSerializer):
pulp_href = DetailIdentityField()
repository_version = NestedRelatedField(
view_name='versions-detail',
Expand Down Expand Up @@ -64,14 +63,14 @@ def validate(self, data):
class Meta:
abstract = True
model = models.Publication
fields = MasterModelSerializer.Meta.fields + (
fields = ModelSerializer.Meta.fields + (
'publisher',
'repository_version',
'repository'
)


class ContentGuardSerializer(MasterModelSerializer):
class ContentGuardSerializer(ModelSerializer):
pulp_href = DetailIdentityField()

name = serializers.CharField(
Expand All @@ -85,13 +84,13 @@ class ContentGuardSerializer(MasterModelSerializer):

class Meta:
model = models.ContentGuard
fields = MasterModelSerializer.Meta.fields + (
fields = ModelSerializer.Meta.fields + (
'name',
'description'
)


class BaseDistributionSerializer(MasterModelSerializer):
class BaseDistributionSerializer(ModelSerializer):
"""
The Serializer for the BaseDistribution model.
Expand Down
13 changes: 6 additions & 7 deletions pulpcore/app/serializers/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
DetailIdentityField,
IdentityField,
LatestVersionField,
MasterModelSerializer,
ModelSerializer,
NestedIdentityField,
NestedRelatedField,
Expand Down Expand Up @@ -48,7 +47,7 @@ class Meta:
'plugin_managed', 'description')


class RemoteSerializer(MasterModelSerializer):
class RemoteSerializer(ModelSerializer):
"""
Every remote defined by a plugin should have a Remote serializer that inherits from this
class. Please import from `pulpcore.plugin.serializers` rather than from this module directly.
Expand Down Expand Up @@ -123,7 +122,7 @@ class RemoteSerializer(MasterModelSerializer):
class Meta:
abstract = True
model = models.Remote
fields = MasterModelSerializer.Meta.fields + (
fields = ModelSerializer.Meta.fields + (
'name', 'url', 'ssl_ca_certificate', 'ssl_client_certificate', 'ssl_client_key',
'ssl_validation', 'proxy_url', 'username', 'password', 'pulp_last_updated',
'download_concurrency', 'policy'
Expand All @@ -150,7 +149,7 @@ class RepositorySyncURLSerializer(serializers.Serializer):
)


class PublisherSerializer(MasterModelSerializer):
class PublisherSerializer(ModelSerializer):
"""
Every publisher defined by a plugin should have an Publisher serializer that inherits from this
class. Please import from `pulpcore.plugin.serializers` rather than from this module directly.
Expand All @@ -168,12 +167,12 @@ class PublisherSerializer(MasterModelSerializer):
class Meta:
abstract = True
model = models.Publisher
fields = MasterModelSerializer.Meta.fields + (
fields = ModelSerializer.Meta.fields + (
'name', 'pulp_last_updated',
)


class ExporterSerializer(MasterModelSerializer):
class ExporterSerializer(ModelSerializer):
pulp_href = DetailIdentityField()
name = serializers.CharField(
help_text=_('The exporter unique name.'),
Expand All @@ -191,7 +190,7 @@ class ExporterSerializer(MasterModelSerializer):
class Meta:
abstract = True
model = models.Exporter
fields = MasterModelSerializer.Meta.fields + (
fields = ModelSerializer.Meta.fields + (
'name',
'pulp_last_updated',
'last_export',
Expand Down

0 comments on commit 2a62d16

Please sign in to comment.