我是否需要在 Django Rest Framework 序列化程序更新中明确使用事务? [英] Do I need to explicitly use transactions with Django Rest Framework serializer updates?
问题描述
根据http://www.django-rest-framework.org/api-guide/serializers/#writable-nested-representations,为了接受嵌套序列化程序,我需要创建一个 update
方法.尽管它们确实修改了多个行/表,但没有一个示例使用事务.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 与您的问题无关.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屋!