Skip to content

pulpcore.plugin.serializers

All serializers documented here should be imported directly from the pulpcore.plugin.serializers namespace.

pulpcore.plugin.serializers

AlternateContentSourceSerializer

Bases: ModelSerializer

Serializer for the AlternateContentSource.

create(validated_data)

Create Alternate Content Source and its path if specified.

update(instance, validated_data)

Update an Alternate Content Source.

AlternateContentSourcePathSerializer

Bases: ModelSerializer

Serializer for the AlternateContentSourcePath.

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.

AsyncOperationResponseSerializer

Bases: Serializer

Serializer for asynchronous operations.

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()

ContentRedirectContentGuardSerializer

Bases: ContentGuardSerializer, GetOrCreateSerializerMixin

A serializer for ContentRedirectContentGuard.

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.

DistributionSerializer

Bases: ModelSerializer

The Serializer for the Distribution model.

The serializer deliberately omits the publication and repository_version field due to plugins typically requiring one or the other but not both.

To include the publication field, it is recommended plugins define the field::

publication = DetailRelatedField( required=False, help_text=_("Publication to be served"), view_name_pattern=r"publications(-./.)?-detail", queryset=models.Publication.objects.exclude(complete=False), allow_null=True, )

To include the repository_version field, it is recommended plugins define the field::

repository_version = RepositoryVersionRelatedField( required=False, help_text=_("RepositoryVersion to be served"), allow_null=True )

Additionally, the serializer omits the remote field, which is used for pull-through caching feature and only by plugins which use publications. Plugins implementing a pull-through caching should define the field in their derived serializer class like this::

remote = DetailRelatedField( required=False, help_text=_('Remote that can be used to fetch content when using pull-through caching.'), queryset=models.Remote.objects.all(), allow_null=True )

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.

ExporterSerializer

Bases: ModelSerializer

Base serializer for Exporters.

validate_path(value, check_is_dir=False) staticmethod

Check if path is in ALLOWED_EXPORT_PATHS.

Parameters:

  • value

    The user-provided value path to be validated.

  • check_is_dir

    If true, insure path ends with a directory

Raises:

  • ValidationError

    When path is not in the ALLOWED_EXPORT_PATHS setting.

Returns:

  • The validated value.

ExportSerializer

Bases: ModelSerializer

Base serializer for Exports.

GetOrCreateSerializerMixin

A mixin that provides a get_or_create with validation in the serializer

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.

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.

ImporterSerializer

Bases: ModelSerializer

Base serializer for Importers.

ImportSerializer

Bases: ModelSerializer

Serializer for Imports.

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.

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.

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

PRNField(**kwargs)

Bases: StringRelatedField

A special IdentityField that shows any object's PRN.

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.

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.

SingleArtifactContentSerializer(*args, **kwargs)

Bases: NoArtifactContentSerializer

Initializer for SingleArtifactContentSerializer

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.

TaskGroupOperationResponseSerializer

Bases: Serializer

Serializer for asynchronous operations that return a task group.

ValidateFieldsMixin

A mixin for validating unknown serializers' fields.

NoArtifactContentUploadSerializer

Bases: UploadSerializerFieldsMixin, NoArtifactContentSerializer

A serializer for content types with no Artifact.

create(validated_data)

Create a new content and remove the already parsed file from validated_data.

SingleArtifactContentUploadSerializer(*args, **kwargs)

Bases: UploadSerializerFieldsMixin, SingleArtifactContentSerializer

A serializer for content_types with a single Artifact.

The Artifact can either be specified via it's url or an uncommitted upload, or a new file can be uploaded in the POST data. Additionally a repository can be specified, to which the content unit will be added.

When using this serializer, the creation of the real content must be wrapped in a task that touches the Artifact and locks the Upload and Repository when specified.

Initializer for SingleArtifactContentUploadSerializer.

deferred_validate(data)

Validate the content unit by deeply analyzing the specified Artifact.

This is only called when validating without a request context to prevent stalling an ongoing http request. It should be overwritten by plugins to extract metadata from the actual content in much the same way as validate. When overwriting, plugins must super-call this method to handle uploads before analyzing the artifact.

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.