Skip to content

Commit daa8efd

Browse files
gerrod3patchback[bot]
authored andcommitted
Merge pull request #751 from pedro-psb/fix/type-regression-on-drf-spectacular
Fix Any serializer type regression breaking Ruby bindings (cherry picked from commit 4d8e8db)
1 parent 89f1e6b commit daa8efd

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

CHANGES/+fix-any-type.bugfix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed the JSONField specification so it doesn't break ruby bindings.
2+
See context [here](https://github.com/pulp/pulp_rpm/issues/3639).

pulp_python/app/fields.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from drf_spectacular.utils import extend_schema_field
2+
from drf_spectacular.types import OpenApiTypes
3+
from rest_framework import serializers
4+
5+
6+
@extend_schema_field(OpenApiTypes.OBJECT)
7+
class JSONObjectField(serializers.JSONField):
8+
"""A drf JSONField override to force openapi schema to use 'object' type.
9+
10+
Not strictly correct, but we relied on that for a long time.
11+
See: https://github.com/tfranzel/drf-spectacular/issues/1095
12+
"""

pulp_python/app/pypi/serializers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from rest_framework import serializers
55
from pulp_python.app.utils import DIST_EXTENSIONS
6+
from pulp_python.app import fields
67
from pulpcore.plugin.models import Artifact
78
from django.db.utils import IntegrityError
89

@@ -27,9 +28,9 @@ class PackageMetadataSerializer(serializers.Serializer):
2728
"""
2829

2930
last_serial = serializers.IntegerField(help_text=_("Cache value from last PyPI sync"))
30-
info = serializers.JSONField(help_text=_("Core metadata of the package"))
31-
releases = serializers.JSONField(help_text=_("List of all the releases of the package"))
32-
urls = serializers.JSONField()
31+
info = fields.JSONObjectField(help_text=_("Core metadata of the package"))
32+
releases = fields.JSONObjectField(help_text=_("List of all the releases of the package"))
33+
urls = fields.JSONObjectField()
3334

3435

3536
class PackageUploadSerializer(serializers.Serializer):

pulp_python/app/serializers.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pulpcore.plugin import serializers as core_serializers
88

99
from pulp_python.app import models as python_models
10+
from pulp_python.app import fields
1011
from pulp_python.app.utils import get_project_metadata_from_artifact, parse_project_metadata
1112

1213

@@ -154,7 +155,7 @@ class PythonPackageContentSerializer(core_serializers.SingleArtifactContentUploa
154155
required=False, allow_blank=True,
155156
help_text=_('A browsable URL for the project and a label for it, separated by a comma.')
156157
)
157-
project_urls = serializers.JSONField(
158+
project_urls = fields.JSONObjectField(
158159
required=False, default=dict,
159160
help_text=_('A dictionary of labels and URLs for the project.')
160161
)
@@ -167,28 +168,28 @@ class PythonPackageContentSerializer(core_serializers.SingleArtifactContentUploa
167168
required=False, allow_blank=True,
168169
help_text=_('Field to specify the OS and CPU for which the binary package was compiled. ')
169170
)
170-
requires_dist = serializers.JSONField(
171+
requires_dist = fields.JSONObjectField(
171172
required=False, default=list,
172173
help_text=_('A JSON list containing names of some other distutils project '
173174
'required by this distribution.')
174175
)
175-
provides_dist = serializers.JSONField(
176+
provides_dist = fields.JSONObjectField(
176177
required=False, default=list,
177178
help_text=_('A JSON list containing names of a Distutils project which is contained'
178179
' within this distribution.')
179180
)
180-
obsoletes_dist = serializers.JSONField(
181+
obsoletes_dist = fields.JSONObjectField(
181182
required=False, default=list,
182183
help_text=_('A JSON list containing names of a distutils project\'s distribution which '
183184
'this distribution renders obsolete, meaning that the two projects should not '
184185
'be installed at the same time.')
185186
)
186-
requires_external = serializers.JSONField(
187+
requires_external = fields.JSONObjectField(
187188
required=False, default=list,
188189
help_text=_('A JSON list containing some dependency in the system that the distribution '
189190
'is to be used.')
190191
)
191-
classifiers = serializers.JSONField(
192+
classifiers = fields.JSONObjectField(
192193
required=False, default=list,
193194
help_text=_('A JSON list containing classification values for a Python package.')
194195
)

0 commit comments

Comments
 (0)