Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/plugin_api/+pulp-labels-api.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Exposed `PulpLabelsField` and `pulp_labels_validator` to the plugin API.
1 change: 1 addition & 0 deletions pulpcore/app/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
JSONDictField,
JSONListField,
LatestVersionField,
PulpLabelsField,
SingleContentArtifactField,
RepositoryVersionsIdentityFromRepositoryField,
RepositoryVersionRelatedField,
Expand Down
2 changes: 1 addition & 1 deletion pulpcore/app/serializers/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
10 changes: 10 additions & 0 deletions pulpcore/app/serializers/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions pulpcore/plugin/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
ProgressReportSerializer,
PRNField,
PublicationSerializer,
PulpLabelsField,
pulp_labels_validator,
RelatedField,
RemoteSerializer,
RepositorySerializer,
Expand Down Expand Up @@ -74,6 +76,8 @@
"ProgressReportSerializer",
"PRNField",
"PublicationSerializer",
"PulpLabelsField",
"pulp_labels_validator",
"RelatedField",
"RemoteSerializer",
"RepositorySerializer",
Expand Down