Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to explicitly use transactions with Django Rest Framework serializer updates?

According to http://www.django-rest-framework.org/api-guide/serializers/#writable-nested-representations, in order to accept a nested serializer I need to create an update method. None of the examples use transactions although they do modify multiple rows/tables. Does the DRF somehow wrap things in transactions already, or should I explicitly put transaction.atomic() all over it?

Related PR:

  • https://github.com/tomchristie/django-rest-framework/pull/1787
like image 686
Scott Stafford Avatar asked Jan 08 '16 13:01

Scott Stafford


1 Answers

first import transaction module from db, and then use the following

with transtaction.atomic():
    pass

This will ensure the atomicity and consistency of your data into database.

like image 150
Abdul Gaffar Avatar answered Oct 06 '22 23:10

Abdul Gaffar