I have a sequence of methods to use in another method call ie handle of a management/command in 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? 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. Please revert.I am using django 1.6.5 on linux
I had the simmilar issue and I was using 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.