Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Any serializer type regression breaking Ruby bindings #751

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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