gpt4 book ai didi

django - 为什么我应该关心 django-revision 操作是原子的?

转载 作者:行者123 更新时间:2023-12-02 01:39:26 25 4
gpt4 key购买 nike

我想开始使用 django-reversion。似乎最简单的方法是使用他们的中间件。但它给出了以下警告:

Warning: Due to changes in the Django 1.6 transaction handling, revision data will be saved in a separate database transaction to the one used to save your models, even if you set ATOMIC_REQUESTS = True.

如果请求不是原子的,有什么注意事项?这似乎表明可能存在某种竞争条件。他们怎么会长得像?我需要注意什么?

感谢您的宝贵时间。抱歉拼写错误我不是母语人士。

最佳答案

如警告中所述,由于 django 从 1.6 开始处理事务的方式发生了一些变化,中间件不再与 View 函数包装在同一事务中。

这在下面讨论 issue at django-reversion .

在实践中,由于 RevisionMiddleware 在保存模型的事务之外运行,因此无法在数据库级别严格保证也将保存恢复数据。

随后不鼓励使用 RevisionMiddlewareThe following practice is advised :

If you need to ensure that your models and revisions are saved in the save transaction, please use the reversion.create_revision() context manager or decorator in combination with transaction.atomic()

这样,您可以确保 reversion_data 将始终与模型数据一起保存。我希望这会有所帮助。

关于django - 为什么我应该关心 django-revision 操作是原子的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29334832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com