Skip to content

Commit

Permalink
Release 5.2.6
Browse files Browse the repository at this point in the history
#### Changelog:
* Fix(backend): Passthrough ReturnDict/ReturnList on identical serializers with @action.
  • Loading branch information
onegreyonewhite committed Dec 20, 2022
1 parent a3d6935 commit 7804d83
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion vstutils/__init__.py
@@ -1,2 +1,2 @@
# pylint: disable=django-not-available
__version__: str = '5.2.5'
__version__: str = '5.2.6'
17 changes: 14 additions & 3 deletions vstutils/api/actions.py
Expand Up @@ -5,6 +5,7 @@
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.decorators import action
from rest_framework.utils.serializer_helpers import ReturnDict, ReturnList
from drf_yasg.utils import swagger_auto_schema

from .responses import HTTP_200_OK, HTTP_201_CREATED, HTTP_204_NO_CONTENT
Expand Down Expand Up @@ -153,13 +154,23 @@ def action_method(
**kwargs,
) -> _t.Union[Response, FileResponse]:

result_serializer_class = self.result_serializer_class or view.get_serializer_class()
result_serializer_class: _t.Type[serializers.Serializer] = self.result_serializer_class # type: ignore
identical = False
if result_serializer_class is None:
result_serializer_class = view.get_serializer_class() # type: ignore
identical = True

result = method(view, request, *args, **kwargs)
response_class = self.method_response_mapping[_t.cast(_t.Text, request.method)]

if issubclass(result_serializer_class, serializers.Serializer):
serializer = result_serializer_class(result, many=self.is_list, context=view.get_serializer_context())
result = serializer.data
if not (isinstance(result, (ReturnDict, ReturnList)) and identical):
serializer = result_serializer_class(
result,
many=self.is_list,
context=view.get_serializer_context()
)
result = serializer.data
elif isinstance(result, FileResponse):
return result

Expand Down

0 comments on commit 7804d83

Please sign in to comment.