Skip to content

Commit

Permalink
Fix Any serializer type regression breaking Ruby bindings
Browse files Browse the repository at this point in the history
See pulp/pulp_rpm#3639

(cherry picked from commit 58425d7)
  • Loading branch information
pedro-psb authored and patchback[bot] committed Oct 29, 2024
1 parent 3d5d2a7 commit 620610f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES/+fix-any-type.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed the JSONField specification so it doesn't break ruby bindings.
See context [here](https://github.com/pulp/pulp_rpm/issues/3639).
2 changes: 1 addition & 1 deletion pulpcore/app/serializers/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ class GoogleSettingsSerializer(BaseSettingsClass):

bucket_name = serializers.CharField(required=True)
project_id = serializers.CharField(required=True)
# credentials = serializers.JSONField(write_only=True) # Need better upstream support
# credentials = fields.JSONDictField(write_only=True) # Need better upstream support
custom_endpoint = serializers.CharField(allow_null=True, default=None)
location = serializers.CharField(allow_blank=True, default="")
default_acl = serializers.CharField(allow_null=True, default=None)
Expand Down
7 changes: 4 additions & 3 deletions pulpcore/app/serializers/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
RelatedField,
RelatedResourceField,
RepositoryVersionRelatedField,
fields,
)
from pulpcore.constants import FS_EXPORT_CHOICES, FS_EXPORT_METHODS

Expand Down Expand Up @@ -103,7 +104,7 @@ class ExportSerializer(ModelSerializer):
view_name="None", # This is a polymorphic field. The serializer does not need a view name.
)

params = serializers.JSONField(
params = fields.JSONDictField(
help_text=_("Any additional parameters that were used to create the export."),
read_only=True,
)
Expand All @@ -118,12 +119,12 @@ class PulpExportSerializer(ExportSerializer):
Serializer for PulpExports.
"""

output_file_info = serializers.JSONField(
output_file_info = fields.JSONDictField(
help_text=_("Dictionary of filename: sha256hash entries for export-output-file(s)"),
read_only=True,
)

toc_info = serializers.JSONField(
toc_info = fields.JSONDictField(
help_text=_("Filename and sha256-checksum of table-of-contents for this export"),
read_only=True,
)
Expand Down
11 changes: 11 additions & 0 deletions pulpcore/app/serializers/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from urllib.parse import urljoin

from django.conf import settings
from drf_spectacular.utils import extend_schema_field
from drf_spectacular.types import OpenApiTypes
from rest_framework import serializers
from rest_framework.fields import empty

Expand All @@ -19,6 +21,15 @@ def relative_path_validator(relative_path):
)


@extend_schema_field(OpenApiTypes.OBJECT)
class JSONDictField(serializers.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
"""


class SingleContentArtifactField(RelatedField):
"""
A serializer field for the '_artifacts' ManyToManyField on the Content model (single-artifact).
Expand Down
3 changes: 2 additions & 1 deletion pulpcore/app/serializers/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ModelSerializer,
RelatedField,
ValidateFieldsMixin,
fields,
)


Expand Down Expand Up @@ -40,7 +41,7 @@ class ImportSerializer(ModelSerializer):
view_name="tasks-detail",
)

params = serializers.JSONField(
params = fields.JSONDictField(
help_text=_("Any parameters that were used to create the import."),
)

Expand Down
3 changes: 2 additions & 1 deletion pulpcore/app/serializers/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
RelatedField,
RelatedResourceField,
TaskGroupStatusCountField,
fields,
)
from pulpcore.constants import TASK_STATES
from pulpcore.app.util import reverse
Expand Down Expand Up @@ -46,7 +47,7 @@ class TaskSerializer(ModelSerializer):
help_text=_("Timestamp of when this task stopped execution."), read_only=True
)
error = serializers.DictField(
child=serializers.JSONField(),
child=fields.JSONDictField(),
help_text=_(
"A JSON Object of a fatal error encountered during the execution of this task."
),
Expand Down

0 comments on commit 620610f

Please sign in to comment.