From 90df67477bf29f400ac9594ea629c32c99b02a4e Mon Sep 17 00:00:00 2001 From: faucomte97 Date: Wed, 18 Sep 2024 16:58:36 +0100 Subject: [PATCH 1/2] fix: Wrap dicts everywhere --- codeforlife/tests/model_view_set.py | 2 +- codeforlife/views/model.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/codeforlife/tests/model_view_set.py b/codeforlife/tests/model_view_set.py index 4ce34499..855bbf02 100644 --- a/codeforlife/tests/model_view_set.py +++ b/codeforlife/tests/model_view_set.py @@ -729,7 +729,7 @@ def assert_serialized_model_equals_json_model( model_serializer = model_view_set.get_serializer(model) # Serialize the model. - serialized_model = model_serializer.data + serialized_model = dict(model_serializer.data) # Recursively convert all datetimes to strings. def datetime_values_to_representation(data: DataDict): diff --git a/codeforlife/views/model.py b/codeforlife/views/model.py index 14ed52fa..7a030507 100644 --- a/codeforlife/views/model.py +++ b/codeforlife/views/model.py @@ -183,9 +183,9 @@ def bulk_create(self, request: Request[RequestUser]): serializer.is_valid(raise_exception=True) self.perform_bulk_create(serializer) return Response( - serializer.data, + dict(serializer.data), status=status.HTTP_201_CREATED, - headers=self.get_success_headers(serializer.data), + headers=self.get_success_headers(dict(serializer.data)), ) def perform_bulk_create( @@ -224,7 +224,7 @@ def bulk_partial_update(self, request: Request[RequestUser]): ) serializer.is_valid(raise_exception=True) self.perform_bulk_update(serializer) - return Response(serializer.data) + return Response(dict(serializer.data)) def perform_bulk_update( self, serializer: "ModelListSerializer[RequestUser, AnyModel]" @@ -303,7 +303,9 @@ def update( ) serializer.is_valid(raise_exception=True) serializer.save() - return Response(**(response_kwargs or {}), data=serializer.data) + return Response( + **(response_kwargs or {}), data=dict(serializer.data) + ) update.__name__ = name From 2a332a29516a0edea8781aab0a8ce6d98660b3e3 Mon Sep 17 00:00:00 2001 From: faucomte97 Date: Wed, 18 Sep 2024 17:01:41 +0100 Subject: [PATCH 2/2] Revert real one --- codeforlife/views/model.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/codeforlife/views/model.py b/codeforlife/views/model.py index 7a030507..14ed52fa 100644 --- a/codeforlife/views/model.py +++ b/codeforlife/views/model.py @@ -183,9 +183,9 @@ def bulk_create(self, request: Request[RequestUser]): serializer.is_valid(raise_exception=True) self.perform_bulk_create(serializer) return Response( - dict(serializer.data), + serializer.data, status=status.HTTP_201_CREATED, - headers=self.get_success_headers(dict(serializer.data)), + headers=self.get_success_headers(serializer.data), ) def perform_bulk_create( @@ -224,7 +224,7 @@ def bulk_partial_update(self, request: Request[RequestUser]): ) serializer.is_valid(raise_exception=True) self.perform_bulk_update(serializer) - return Response(dict(serializer.data)) + return Response(serializer.data) def perform_bulk_update( self, serializer: "ModelListSerializer[RequestUser, AnyModel]" @@ -303,9 +303,7 @@ def update( ) serializer.is_valid(raise_exception=True) serializer.save() - return Response( - **(response_kwargs or {}), data=dict(serializer.data) - ) + return Response(**(response_kwargs or {}), data=serializer.data) update.__name__ = name