Skip to content

Commit 16758f3

Browse files
gerrod3mdellweg
authored andcommitted
Add pulp-label serializer helpers to plugin api
Assisted by: claude-4.5-sonnet (cherry picked from commit 9b0aa39)
1 parent 24dc16e commit 16758f3

5 files changed

Lines changed: 17 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Exposed `PulpLabelsField` and `pulp_labels_validator` to the plugin API.

pulpcore/app/serializers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
JSONDictField,
3434
JSONListField,
3535
LatestVersionField,
36+
PulpLabelsField,
3637
SingleContentArtifactField,
3738
RepositoryVersionsIdentityFromRepositoryField,
3839
RepositoryVersionRelatedField,

pulpcore/app/serializers/content.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class NoArtifactContentSerializer(base.ModelSerializer):
1313
pulp_href = base.DetailIdentityField(view_name_pattern=r"contents(-.*/.*)-detail")
14-
pulp_labels = serializers.HStoreField(
14+
pulp_labels = fields.PulpLabelsField(
1515
help_text=_(
1616
"A dictionary of arbitrary key/value pairs used to describe a specific "
1717
"Content instance."

pulpcore/app/serializers/fields.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,13 @@ def pulp_labels_validator(value):
435435
)
436436

437437
return value
438+
439+
440+
class PulpLabelsField(serializers.HStoreField):
441+
"""
442+
Custom field for handling pulp labels that ensures proper dictionary format.
443+
Converts JSON strings to dictionaries during validation.
444+
"""
445+
446+
def get_value(self, dictionary):
447+
return dictionary.get(self.field_name, empty)

pulpcore/plugin/serializers/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
ProgressReportSerializer,
2727
PRNField,
2828
PublicationSerializer,
29+
PulpLabelsField,
30+
pulp_labels_validator,
2931
RelatedField,
3032
RemoteSerializer,
3133
RepositorySerializer,
@@ -74,6 +76,8 @@
7476
"ProgressReportSerializer",
7577
"PRNField",
7678
"PublicationSerializer",
79+
"PulpLabelsField",
80+
"pulp_labels_validator",
7781
"RelatedField",
7882
"RemoteSerializer",
7983
"RepositorySerializer",

0 commit comments

Comments
 (0)