Skip to content

Commit

Permalink
Merge pull request #753 from pulp/patchback/backports/3.12/4d8e8db608…
Browse files Browse the repository at this point in the history
…c80e3829b4c3ee90e84d7ef69c5236/pr-751

[PR #751/4d8e8db6 backport][3.12] Fix Any serializer type regression breaking Ruby bindings
  • Loading branch information
gerrod3 authored Oct 25, 2024
2 parents 8f3f697 + f19bbcd commit fbc16cc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 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_python/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
"""
7 changes: 4 additions & 3 deletions pulp_python/app/pypi/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from rest_framework import serializers
from pulp_python.app.utils import DIST_EXTENSIONS
from pulp_python.app import fields
from pulpcore.plugin.models import Artifact
from pulpcore.plugin.util import get_domain
from django.db.utils import IntegrityError
Expand All @@ -28,9 +29,9 @@ class PackageMetadataSerializer(serializers.Serializer):
"""

last_serial = serializers.IntegerField(help_text=_("Cache value from last PyPI sync"))
info = serializers.JSONField(help_text=_("Core metadata of the package"))
releases = serializers.JSONField(help_text=_("List of all the releases of the package"))
urls = serializers.JSONField()
info = fields.JSONObjectField(help_text=_("Core metadata of the package"))
releases = fields.JSONObjectField(help_text=_("List of all the releases of the package"))
urls = fields.JSONObjectField()


class PackageUploadSerializer(serializers.Serializer):
Expand Down
13 changes: 7 additions & 6 deletions pulp_python/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pulpcore.plugin.util import get_domain

from pulp_python.app import models as python_models
from pulp_python.app import fields
from pulp_python.app.utils import get_project_metadata_from_artifact, parse_project_metadata


Expand Down Expand Up @@ -157,7 +158,7 @@ class PythonPackageContentSerializer(core_serializers.SingleArtifactContentUploa
required=False, allow_blank=True,
help_text=_('A browsable URL for the project and a label for it, separated by a comma.')
)
project_urls = serializers.JSONField(
project_urls = fields.JSONObjectField(
required=False, default=dict,
help_text=_('A dictionary of labels and URLs for the project.')
)
Expand All @@ -170,28 +171,28 @@ class PythonPackageContentSerializer(core_serializers.SingleArtifactContentUploa
required=False, allow_blank=True,
help_text=_('Field to specify the OS and CPU for which the binary package was compiled. ')
)
requires_dist = serializers.JSONField(
requires_dist = fields.JSONObjectField(
required=False, default=list,
help_text=_('A JSON list containing names of some other distutils project '
'required by this distribution.')
)
provides_dist = serializers.JSONField(
provides_dist = fields.JSONObjectField(
required=False, default=list,
help_text=_('A JSON list containing names of a Distutils project which is contained'
' within this distribution.')
)
obsoletes_dist = serializers.JSONField(
obsoletes_dist = fields.JSONObjectField(
required=False, default=list,
help_text=_('A JSON list containing names of a distutils project\'s distribution which '
'this distribution renders obsolete, meaning that the two projects should not '
'be installed at the same time.')
)
requires_external = serializers.JSONField(
requires_external = fields.JSONObjectField(
required=False, default=list,
help_text=_('A JSON list containing some dependency in the system that the distribution '
'is to be used.')
)
classifiers = serializers.JSONField(
classifiers = fields.JSONObjectField(
required=False, default=list,
help_text=_('A JSON list containing classification values for a Python package.')
)
Expand Down

0 comments on commit fbc16cc

Please sign in to comment.