我需要明确地使用Django Rest Framework序列化程序更新的事务吗? [英] Do I need to explicitly use transactions with Django Rest Framework serializer updates?

查看:578
本文介绍了我需要明确地使用Django Rest Framework序列化程序更新的事务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 http://www.django -rest-framework.org/api-guide/serializers/#writable-nested-representations ,为了接受嵌套的序列化程序,我需要创建一个更新方法。没有一个示例使用事务,尽管它们修改多个行/表。 DRF是否以某种方式将事物包装在事务中,或者我应该明确地将 transaction.atomic()全部覆盖?

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?

相关PR:

  • https://github.com/tomchristie/django-rest-framework/pull/1787

推荐答案

相关PR与您的问题无关。 PR链接到绕过默认Django事务方案的DRF特定异常处理程序( https://github.com/tomchristie/django-rest-framework/pull/1204#issuecomment-52712621 )。

The related PR is unrelated to your question. PR is linked to the DRF specific exception handler that bypassed the default Django transaction scheme (https://github.com/tomchristie/django-rest-framework/pull/1204#issuecomment-52712621).

DRF不特别是将事物包装在一个交易中,让用户随意选择他们想要的任何东西。

DRF doesn't specifically wrap things in a transaction to leave the users free to choose whatever they want to.

这篇关于我需要明确地使用Django Rest Framework序列化程序更新的事务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆