Skip to content

Commit

Permalink
Fix Any serializer type regression breaking Ruby bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-psb committed Oct 24, 2024
1 parent 72da970 commit 398189e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 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).
12 changes: 12 additions & 0 deletions pulp_ansible/app/fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from drf_spectacular.utils import extend_schema_field
from drf_spectacular.types import OpenApiTypes
from rest_framework import serializers


@extend_schema_field(OpenApiTypes.OBJECT)
class JSONObjectField(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
"""
10 changes: 6 additions & 4 deletions pulp_ansible/app/galaxy/v3/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from rest_framework.reverse import reverse
from rest_framework import serializers, relations

from pulp_ansible.app import models, serializers as ansible_serializers
from pulp_ansible.app import models, fields, serializers as ansible_serializers
from pulpcore.plugin.models import RepositoryVersion
from pulpcore.plugin import serializers as core_serializers

Expand Down Expand Up @@ -294,10 +294,12 @@ class CollectionVersionSerializer(UnpaginatedCollectionVersionSerializer):
A serializer for a CollectionVersion.
"""

manifest = serializers.JSONField(
manifest = fields.JSONObjectField(
help_text="A JSON field holding MANIFEST.json data.", read_only=True
)
files = serializers.JSONField(help_text="A JSON field holding FILES.json data.", read_only=True)
files = fields.JSONObjectField(
help_text="A JSON field holding FILES.json data.", read_only=True
)

class Meta:
model = models.CollectionVersion
Expand All @@ -310,7 +312,7 @@ class Meta:
class CollectionVersionDocsSerializer(serializers.ModelSerializer):
"""A serializer to display the docs_blob of a CollectionVersion."""

docs_blob = serializers.JSONField()
docs_blob = fields.JSONObjectField()

class Meta:
fields = ("docs_blob",)
Expand Down
17 changes: 9 additions & 8 deletions pulp_ansible/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
Role,
Tag,
)
from pulp_ansible.app import fields
from pulp_ansible.app.schema import COPY_CONFIG_SCHEMA
from pulp_ansible.app.tasks.utils import (
parse_collections_requirements_file,
Expand Down Expand Up @@ -578,11 +579,11 @@ class CollectionVersionSerializer(ContentChecksumSerializer, CollectionVersionUp
read_only=True,
)

contents = serializers.JSONField(
contents = fields.JSONObjectField(
help_text=_("A JSON field with data about the contents."), read_only=True
)

dependencies = serializers.JSONField(
dependencies = fields.JSONObjectField(
help_text=_(
"A dict declaring Collections that this collection requires to be installed for it to "
"be usable."
Expand All @@ -596,16 +597,16 @@ class CollectionVersionSerializer(ContentChecksumSerializer, CollectionVersionUp
read_only=True,
)

docs_blob = serializers.JSONField(
docs_blob = fields.JSONObjectField(
help_text=_("A JSON field holding the various documentation blobs in the collection."),
read_only=True,
)

manifest = serializers.JSONField(
manifest = fields.JSONObjectField(
help_text=_("A JSON field holding MANIFEST.json data."), read_only=True
)

files = serializers.JSONField(
files = fields.JSONObjectField(
help_text=_("A JSON field holding FILES.json data."), read_only=True
)

Expand Down Expand Up @@ -1030,8 +1031,8 @@ class CollectionImportDetailSerializer(CollectionImportListSerializer):
A serializer for a CollectionImport detail view.
"""

error = serializers.JSONField(source="task.error", required=False)
messages = serializers.JSONField()
error = fields.JSONObjectField(source="task.error", required=False)
messages = fields.JSONObjectField()

class Meta(CollectionImportListSerializer.Meta):
fields = CollectionImportListSerializer.Meta.fields + ("error", "messages")
Expand Down Expand Up @@ -1076,7 +1077,7 @@ class CopySerializer(serializers.Serializer):
A serializer for Content Copy API.
"""

config = serializers.JSONField(
config = fields.JSONObjectField(
help_text=_("A JSON document describing sources, destinations, and content to be copied"),
)

Expand Down

0 comments on commit 398189e

Please sign in to comment.