From ee31c1fa4a7ff8ed9bfc61f1aec0bc5bfd368847 Mon Sep 17 00:00:00 2001 From: Oliver Sauder Date: 2025年9月23日 20:29:10 +0400 Subject: [PATCH] Deprecated support for django-polymorphic resources Desired for Django Polymorphic support to be added in an external 3rd party library in case there is a demand and someone is to be found who will take the lead. --- CHANGELOG.md | 4 ++++ docs/usage.md | 11 +++++++++++ rest_framework_json_api/serializers.py | 11 +++++++++++ setup.cfg | 1 + 4 files changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ec34d46..01bb9e5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ any parts of the framework not mentioned in the documentation should generally b * Ensured that an empty `included` array is returned in responses when the `include` query parameter is present but no related resources exist. +### Deprecated + +* Deprecated support for using Polymorphic resources through [django-polymorphic](https://github.com/jazzband/django-polymorphic). There is currently no replacement. In case you are affected of this change please join [our discussion](https://github.com/django-json-api/django-rest-framework-json-api/discussions/1194). + ## [8.0.0] - 2025年07月24日 ### Added diff --git a/docs/usage.md b/docs/usage.md index 00c12ee8..f3c09d7d 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -863,6 +863,17 @@ field_name_mapping = { ### Working with polymorphic resources +-- + +**Deprecation notice:** + + +Support for using Polymorphic resources through [django-polymorphic](https://github.com/jazzband/django-polymorphic) is deprecated and will be removed in a future release. + +There is currently no replacement. In case you are affected of this change please join [our discussion](https://github.com/django-json-api/django-rest-framework-json-api/discussions/1194). + +--- + Polymorphic resources allow you to use specialized subclasses without requiring special endpoints to expose the specialized versions. For example, if you had a `Project` that could be either an `ArtProject` or a `ResearchProject`, you can diff --git a/rest_framework_json_api/serializers.py b/rest_framework_json_api/serializers.py index 26f6b02e..5583d3b9 100644 --- a/rest_framework_json_api/serializers.py +++ b/rest_framework_json_api/serializers.py @@ -1,3 +1,4 @@ +import warnings from collections.abc import Mapping from django.core.exceptions import ObjectDoesNotExist @@ -342,6 +343,16 @@ def __new__(cls, name, bases, attrs): if not parents: return new_class + warnings.warn( + DeprecationWarning( + "Support for polymorphic resources is deprecated." + "There is currently no replacement. In case you are affected of this " + "change please join discussion at " + "https://github.com/django-json-api/django-rest-framework-json-api/discussions/1194." + ), + stacklevel=2, + ) + polymorphic_serializers = getattr(new_class, "polymorphic_serializers", None) assert ( polymorphic_serializers is not None diff --git a/setup.cfg b/setup.cfg index 92606700..05c3bd26 100644 --- a/setup.cfg +++ b/setup.cfg @@ -63,6 +63,7 @@ DJANGO_SETTINGS_MODULE=example.settings.test filterwarnings = error::DeprecationWarning error::PendingDeprecationWarning + ignore:Support for polymorphic resources is deprecated testpaths = example tests

AltStyle によって変換されたページ (->オリジナル) /