Response 4xx rolls back database

11 views
Skip to first unread message

theo

unread,
Mar 30, 2020, 12:43:55 PM3/30/20
to Django REST framework
Hey

I have noticed today that 4xx Responses roll back the database

I have my return statement from my ApiView as follows: 

      return Response(serializer.errors, status=400)

and I want to update a model instance with some details but they are not saved.


When I change the status to 2xx the model instance changes are saved successfuly


I've found this related issue here:


I am using django rest version 3.7.7

Any help appriciated!

Thanks a lot!

Linovia

unread,
Mar 30, 2020, 1:21:19 PM3/30/20
to Django REST framework
Hi,

If you want to apply changes and return a 400 error code, you’ll need to commit the current transaction.
Browse the Django documentation about transaction and you’ll find how to do that.

Regards,
Xavier O.
Linovia.
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/6ad2abd8-ae9e-402a-b3a3-f2069c269a0a%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages