Skip to content

Commit

Permalink
selectively distinguish real serializers from mocked ones #1006
Browse files Browse the repository at this point in the history
This addresses an issue where we enter a code path that only
works for real serializers, while the check also allows for objects
covered by OpenApiSerializerExtension.
However when checking for customized ListSerializers, we are only
interested in actual serializers so distinguish the cases.
  • Loading branch information
tfranzel committed Jun 20, 2023
1 parent ae52f23 commit 5fe55a1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drf_spectacular/plumbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ def force_instance(serializer_or_field):
return serializer_or_field


def is_serializer(obj) -> bool:
def is_serializer(obj, strict=False) -> bool:
from drf_spectacular.serializers import OpenApiSerializerExtension
return (
isinstance(force_instance(obj), serializers.BaseSerializer)
or bool(OpenApiSerializerExtension.get_match(obj))
or (bool(OpenApiSerializerExtension.get_match(obj)) and not strict)
)


Expand All @@ -119,7 +119,7 @@ def get_list_serializer(obj):

def is_list_serializer_customized(obj) -> bool:
return (
is_serializer(obj)
is_serializer(obj, strict=True)
and get_class(get_list_serializer(obj)).to_representation # type: ignore
is not serializers.ListSerializer.to_representation
)
Expand Down

0 comments on commit 5fe55a1

Please sign in to comment.