From 5cc3da77f939b296fe544d262e6140c89760524b Mon Sep 17 00:00:00 2001 From: Pedro Brochado <pedropsb95@gmail.com> Date: Thu, 24 Oct 2024 16:26:03 -0300 Subject: [PATCH] Fix Any serializer type regression breaking Ruby bindings See https://github.com/pulp/pulp_rpm/issues/3639 --- CHANGES/+fix-any-type.bugfix | 2 ++ pulp_container/app/fields.py | 12 ++++++++++++ pulp_container/app/serializers.py | 6 +++--- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 CHANGES/+fix-any-type.bugfix create mode 100644 pulp_container/app/fields.py diff --git a/CHANGES/+fix-any-type.bugfix b/CHANGES/+fix-any-type.bugfix new file mode 100644 index 000000000..89ea25f51 --- /dev/null +++ b/CHANGES/+fix-any-type.bugfix @@ -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). diff --git a/pulp_container/app/fields.py b/pulp_container/app/fields.py new file mode 100644 index 000000000..110d2c55c --- /dev/null +++ b/pulp_container/app/fields.py @@ -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 + """ diff --git a/pulp_container/app/serializers.py b/pulp_container/app/serializers.py index 1287e49fe..5b649cab1 100644 --- a/pulp_container/app/serializers.py +++ b/pulp_container/app/serializers.py @@ -29,7 +29,7 @@ ) from pulp_file.app.models import FileContent -from pulp_container.app import models +from pulp_container.app import models, fields from pulp_container.constants import SIGNATURE_TYPE @@ -84,11 +84,11 @@ class ManifestSerializer(NoArtifactContentSerializer): queryset=models.Blob.objects.all(), ) - annotations = serializers.JSONField( + annotations = fields.JSONObjectField( read_only=True, help_text=_("Property that contains arbitrary metadata stored inside the image manifest."), ) - labels = serializers.JSONField( + labels = fields.JSONObjectField( read_only=True, help_text=_("Property describing metadata stored inside the image configuration"), )