diff --git a/CHANGES/plugin_api/+pulp-labels-api.bugfix b/CHANGES/plugin_api/+pulp-labels-api.bugfix new file mode 100644 index 00000000000..1250cc20f87 --- /dev/null +++ b/CHANGES/plugin_api/+pulp-labels-api.bugfix @@ -0,0 +1 @@ +Exposed `PulpLabelsField` and `pulp_labels_validator` to the plugin API. diff --git a/pulpcore/app/serializers/__init__.py b/pulpcore/app/serializers/__init__.py index 659532a6486..0d22f66dad1 100644 --- a/pulpcore/app/serializers/__init__.py +++ b/pulpcore/app/serializers/__init__.py @@ -33,6 +33,7 @@ JSONDictField, JSONListField, LatestVersionField, + PulpLabelsField, SingleContentArtifactField, RepositoryVersionsIdentityFromRepositoryField, RepositoryVersionRelatedField, diff --git a/pulpcore/app/serializers/content.py b/pulpcore/app/serializers/content.py index f8e2981dceb..fa2c68cf3d2 100644 --- a/pulpcore/app/serializers/content.py +++ b/pulpcore/app/serializers/content.py @@ -11,7 +11,7 @@ class NoArtifactContentSerializer(base.ModelSerializer): pulp_href = base.DetailIdentityField(view_name_pattern=r"contents(-.*/.*)-detail") - pulp_labels = serializers.HStoreField( + pulp_labels = fields.PulpLabelsField( help_text=_( "A dictionary of arbitrary key/value pairs used to describe a specific " "Content instance." diff --git a/pulpcore/app/serializers/fields.py b/pulpcore/app/serializers/fields.py index ac156dbd088..3a3cbe828b8 100644 --- a/pulpcore/app/serializers/fields.py +++ b/pulpcore/app/serializers/fields.py @@ -435,3 +435,13 @@ def pulp_labels_validator(value): ) return value + + +class PulpLabelsField(serializers.HStoreField): + """ + Custom field for handling pulp labels that ensures proper dictionary format. + Converts JSON strings to dictionaries during validation. + """ + + def get_value(self, dictionary): + return dictionary.get(self.field_name, empty) diff --git a/pulpcore/plugin/serializers/__init__.py b/pulpcore/plugin/serializers/__init__.py index 76dc70ea752..cccc43014f7 100644 --- a/pulpcore/plugin/serializers/__init__.py +++ b/pulpcore/plugin/serializers/__init__.py @@ -26,6 +26,8 @@ ProgressReportSerializer, PRNField, PublicationSerializer, + PulpLabelsField, + pulp_labels_validator, RelatedField, RemoteSerializer, RepositorySerializer, @@ -74,6 +76,8 @@ "ProgressReportSerializer", "PRNField", "PublicationSerializer", + "PulpLabelsField", + "pulp_labels_validator", "RelatedField", "RemoteSerializer", "RepositorySerializer",