Skip to content

pulp.app.serializers

All serializers documented here should be imported directly from the pulp.app.serializers namespace.

pulpcore.app.serializers

pulp.app.serializers.base

pulpcore.app.serializers.base

HrefPrnFieldMixin

A mixin to configure related fields to generate relative hrefs and accept PRNs.

IdentityField

Bases: HrefPrnFieldMixin, HyperlinkedIdentityField

IdentityField for use in the pulp_href field of non-Master/Detail Serializers.

When using this field on a serializer, it will serialize the related resource as a relative URL.

RelatedField

Bases: HrefPrnFieldMixin, HyperlinkedRelatedField

RelatedField when relating to non-Master/Detail models

When using this field on a serializer, it will serialize the related resource as a relative URL.

PRNField(**kwargs)

Bases: StringRelatedField

A special IdentityField that shows any object's PRN.

RelatedResourceField

Bases: RelatedField

RelatedResourceField when relating a Resource object models.

This field should be used to relate a list of non-homogeneous resources. e.g.: CreatedResource and ExportedResource models that store relationships to arbitrary resources.

Specific implementation requires the model to be defined in the Meta:.

DetailIdentityField(view_name=None, view_name_pattern=None, **kwargs)

Bases: _DetailFieldMixin, HyperlinkedIdentityField

IdentityField for use in the pulp_href field of Master/Detail Serializers

When using this field on a Serializer, it will automatically cast objects to their Detail type base on the Serializer's Model before generating URLs for them.

Subclasses must indicate the Master model they represent by declaring a queryset in their class body, usually .objects.all().

DetailRelatedField(view_name=None, view_name_pattern=None, **kwargs)

Bases: _DetailFieldMixin, HyperlinkedRelatedField

RelatedField for use when relating to Master/Detail models

When using this field on a Serializer, relate it to the Master model in a Master/Detail relationship, and it will automatically cast objects to their Detail type before generating URLs for them.

Subclasses must indicate the Master model they represent by declaring a queryset in their class body, usually .objects.all().

use_pk_only_optimization()

If the lookup field is pk, DRF substitutes a PKOnlyObject as an optimization. This optimization breaks with Detail fields like this one which need access to their Meta class to get the relevant view_name.

NestedIdentityField

Bases: HrefPrnFieldMixin, NestedHyperlinkedIdentityField

NestedIdentityField for use with nested resources.

When using this field in a serializer, it serializes the resource as a relative URL.

NestedRelatedField

Bases: HrefPrnFieldMixin, NestedHyperlinkedRelatedField

NestedRelatedField for use when relating to nested resources.

When using this field in a serializer, it serializes the related resource as a relative URL.

ValidateFieldsMixin

A mixin for validating unknown serializers' fields.

HiddenFieldsMixin

Bases: Serializer

Adds a list field of hidden (write only) fields and whether their values are set so clients can tell if they are overwriting an existing value. For example this could be any sensitive information such as a password, name or token. The list contains dictionaries with keys name and is_set.

GetOrCreateSerializerMixin

A mixin that provides a get_or_create with validation in the serializer

DomainUniqueValidator

Bases: UniqueValidator

Special UniqueValidator for Models with pulp_domain relations.

filter_queryset(value, queryset, field_name)

Filter by domain first to limit unique check to that domain.

ModelSerializer

Bases: ValidateFieldsMixin, QueryFieldsMixin, HyperlinkedModelSerializer

Base serializer for use with [pulpcore.app.models.Model][]

This ensures that all Serializers provide values for the 'pulp_href` field.

The class provides a default for the ref_name attribute in the ModelSerializers's Meta class. This ensures that the OpenAPI definitions of plugins are namespaced properly.

AsyncOperationResponseSerializer

Bases: Serializer

Serializer for asynchronous operations.

TaskGroupOperationResponseSerializer

Bases: Serializer

Serializer for asynchronous operations that return a task group.

SetLabelSerializer

Bases: Serializer

Serializer for synchronously setting a label.

UnsetLabelSerializer

Bases: Serializer

Serializer for synchronously setting a label.

validate_unknown_fields(initial_data, defined_fields)

This will raise a ValidationError if a serializer is passed fields that are unknown. The csrfmiddlewaretoken field is silently ignored.

pulp.app.serializers.fields

pulpcore.app.serializers.fields

JSONDictField

Bases: JSONField

A drf JSONField override to force openapi schema to use 'object' type.

Not strictly correct, but we relied on that for a long time. See: https://github.com/tfranzel/drf-spectacular/issues/1095

SingleContentArtifactField

Bases: RelatedField

A serializer field for the '_artifacts' ManyToManyField on the Content model (single-artifact).

get_attribute(instance)

Returns the field from the instance that should be serialized using this serializer field.

This serializer looks up the list of artifacts and returns only one, if any exist. If more than one exist, it throws and exception because this serializer is being used in an improper context.

Returns:

  • A single Artifact model related to the instance of Content.

ContentArtifactChecksumField(*args, **kwargs)

Bases: CharField

A serializer field for the artifact checksum Content model (single-artifact).

get_attribute(instance)

Returns the field from the instance that should be serialized using this serializer field.

This serializer looks up the checksum for single artifact content

Returns:

  • A string of the checksum or None.

Raises:

  • [rest_framework.exceptions.ValidationError][]

    When more than one Artifacts exist.

ContentArtifactsField

Bases: DictField

A serializer field for the '_artifacts' ManyToManyField on the Content model.

run_validation(data)

Validates 'data' dict.

Validates that all keys of 'data' are relative paths. Validates that all values of 'data' are URLs for an existing Artifact.

Parameters:

  • data (dict) –

    A dict mapping relative paths inside the Content to the corresponding Artifact URLs.

Returns:

  • A dict mapping relative paths inside the Content to the corresponding Artifact instances.

Raises:

  • [rest_framework.exceptions.ValidationError][]

    When one of the Artifacts does not exist or one of the paths is not a relative path or the field is missing.

get_attribute(instance)

Returns the field from the instance that should be serialized using this serializer field.

This serializer field serializes a ManyToManyField that is actually stored as a ContentArtifact model. Instead of returning the field, this method returns all the ContentArtifact models related to this Content.

Returns:

  • A list of ContentArtifact models related to the instance of Content.

to_representation(value)

Serializes list of ContentArtifacts.

Returns a dict mapping relative paths inside the Content to the corresponding Artifact URLs.

Parameters:

  • value (list of [pulpcore.app.models.ContentArtifact][]) –

    A list of all the ContentArtifacts related to the Content model being serialized.

Returns:

  • A dict where keys are relative path of the artifact inside the Content and values are Artifact URLs.

LatestVersionField(*args, **kwargs)

Bases: RepositoryVersionRelatedField

Unfortunately you can't just set read_only=True on the class. It has to be done explicitly in the kwargs to init, or else DRF complains.

get_attribute(instance)

Parameters:

  • instance (Repository) –

    a repository that has been matched by the current ViewSet.

Returns:

BaseURLField

Bases: CharField

Serializer Field for the base_url field of the Distribution.

TaskGroupStatusCountField(state, *args, **kwargs)

Bases: IntegerField, ReadOnlyField

Serializer field for counting the tasks on a task group in a given state.

pulp_labels_validator(value)

A validator designed for the pulp_labels field.

pulp.app.serializers.content

pulpcore.app.serializers.content

NoArtifactContentSerializer

Bases: ModelSerializer

get_artifacts(validated_data)

Extract artifacts from validated_data.

This function is supposed to extract the information about content artifacts from validated_data and return a dictionary with artifacts and relative paths as keys.

retrieve(validated_data)

Retrieve existing content unit if it exists, else return None.

This method is plugin-specific and implementing it for a specific content type allows for uploading already existing content units of that type.

validate(data)

Validate that we have an Artifact or can create one.

create(validated_data)

Create the content and associate it with its Artifacts, or retrieve the existing content.

Parameters:

  • validated_data (dict) –

    Data to save to the database

SingleArtifactContentSerializer(*args, **kwargs)

Bases: NoArtifactContentSerializer

Initializer for SingleArtifactContentSerializer

ContentChecksumSerializer

Bases: Serializer

Provide a serializer with artifact checksum fields for single artifact content.

If you use this serializer, it's recommended that you prefetch artifacts:

Content.objects.prefetch_related("_artifacts").all()

ArtifactSerializer

Bases: ModelSerializer

validate(data)

Validate file by size and by all checksums provided.

Raises:

  • [rest_framework.exceptions.ValidationError][]

    When the expected file size or any of the checksums don't match their actual values.

SigningServiceSerializer

Bases: ModelSerializer

A serializer for the model declaring a signing service.

pulp.app.serializers.repository

pulpcore.app.serializers.repository

RemoteSerializer

Bases: ModelSerializer, HiddenFieldsMixin

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.

validate_url(url)

Check if the 'url' is a file:// path, and if so, ensure it's an ALLOWED_IMPORT_PATH.

The ALLOWED_IMPORT_PATH is specified as a Pulp setting.

Parameters:

  • url

    The user-provided value for 'url' to be validated.

Raises:

  • ValidationError

    When the url starts with file://, but is not a subfolder of a path in the ALLOWED_IMPORT_PATH setting.

Returns:

  • The validated value.

validate_proxy_url(value)

Check, that the proxy_url does not contain credentials.

validate(data)

Check, that proxy credentials are only provided completely and if a proxy is configured.

ContentSummarySerializer

Bases: Serializer

Serializer for the RepositoryVersion content summary

to_representation(obj)

The summary of contained content.

Returns:

  • dict

    The dictionary has the following format.::

    { 'added': {: {'count': , 'href': }, 'removed': {: {'count': , 'href': }, 'present': {: {'count': , 'href': }, }

to_internal_value(data)

Setting the internal value.