简体   繁体   English

django commit_on_success用法

[英]django commit_on_success usage

I have a sequence of methods to use in another method call ie handle of a management/command in django. 我有一系列方法可用于另一个方法调用,即Django中的管理/命令句柄。 How do I ensure completion of all the methods in the sequence. 如何确保序列中所有方法的完成。 All these methods do not necessarily return a value. 所有这些方法不一定都返回值。 Can I use commit_on_success for the handle? 我可以使用commit_on_success作为句柄吗? Is there any other better method. 还有其他更好的方法吗? Basically some of the methods update some important values in the postgresql tables on the basis of which certain decisions are taken for the next method call. 基本上,某些方法会更新postgresql表中的一些重要值,并根据这些值为下一个方法调用做出某些决策。 Please revert.I am using django 1.6.5 on linux 请还原。我在Linux上使用Django 1.6.5

I had the simmilar issue and I was using transaction.commit_manually . 我遇到了类似的问题,并且正在使用transaction.commit_manually The code I have looks like this: 我的代码如下所示:

# Some actions before
with transaction.commit_manually():
    try:
        # Some actions that will be saved in DB
    except:
        # Log error message
        transaction.rollback() # Rollback if there was an error during the execution
        return error_response # Stop execution of the method and return the response
    transaction.commit() # If return was not initiated before, it means that there were no errors, so we can do commit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM