Skip to content

Commit 4d8e8db

Browse files
authored
Merge pull request #751 from pedro-psb/fix/type-regression-on-drf-spectacular
Fix Any serializer type regression breaking Ruby bindings
2 parents 5cccdff + 195f39c commit 4d8e8db

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 pulpcore.plugin.util import get_domain
89
from django.db.utils import IntegrityError
@@ -28,9 +29,9 @@ class PackageMetadataSerializer(serializers.Serializer):
2829
"""
2930

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

3536

3637
class PackageUploadSerializer(serializers.Serializer):

pulp_python/app/serializers.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pulpcore.plugin.util import get_domain
99

1010
from pulp_python.app import models as python_models
11+
from pulp_python.app import fields
1112
from pulp_python.app.utils import get_project_metadata_from_artifact, parse_project_metadata
1213

1314

@@ -157,7 +158,7 @@ class PythonPackageContentSerializer(core_serializers.SingleArtifactContentUploa
157158
required=False, allow_blank=True,
158159
help_text=_('A browsable URL for the project and a label for it, separated by a comma.')
159160
)
160-
project_urls = serializers.JSONField(
161+
project_urls = fields.JSONObjectField(
161162
required=False, default=dict,
162163
help_text=_('A dictionary of labels and URLs for the project.')
163164
)
@@ -170,28 +171,28 @@ class PythonPackageContentSerializer(core_serializers.SingleArtifactContentUploa
170171
required=False, allow_blank=True,
171172
help_text=_('Field to specify the OS and CPU for which the binary package was compiled. ')
172173
)
173-
requires_dist = serializers.JSONField(
174+
requires_dist = fields.JSONObjectField(
174175
required=False, default=list,
175176
help_text=_('A JSON list containing names of some other distutils project '
176177
'required by this distribution.')
177178
)
178-
provides_dist = serializers.JSONField(
179+
provides_dist = fields.JSONObjectField(
179180
required=False, default=list,
180181
help_text=_('A JSON list containing names of a Distutils project which is contained'
181182
' within this distribution.')
182183
)
183-
obsoletes_dist = serializers.JSONField(
184+
obsoletes_dist = fields.JSONObjectField(
184185
required=False, default=list,
185186
help_text=_('A JSON list containing names of a distutils project\'s distribution which '
186187
'this distribution renders obsolete, meaning that the two projects should not '
187188
'be installed at the same time.')
188189
)
189-
requires_external = serializers.JSONField(
190+
requires_external = fields.JSONObjectField(
190191
required=False, default=list,
191192
help_text=_('A JSON list containing some dependency in the system that the distribution '
192193
'is to be used.')
193194
)
194-
classifiers = serializers.JSONField(
195+
classifiers = fields.JSONObjectField(
195196
required=False, default=list,
196197
help_text=_('A JSON list containing classification values for a Python package.')
197198
)

0 commit comments

Comments
 (0)