Hi, I am just wondering if there is a way to issue a commit operation to the database with conditions.
I take Frappe’s library management system tutorial as example ( https://frappeframework.com/docs/user/en/tutorial/types-of-doctype ).
class LibraryTransaction(Document): def before_submit(self): if self.type == "Issue": self.validate_issue() # set the article status to be Issued article = frappe.get_doc("Article", self.article) article.status = "Issued" article.save() elif self.type == "Return": self.validate_return() # set the article status to be Available article = frappe.get_doc("Article", self.article) article.status = "Available" article.save()
The transaction is validated before commit. But how do I make sure that the status of the article does not change between the validation and commit? Lets say, I wish to borrow a book which is available at the time of validation. But someone has borrowed it just 0.00001 seconds before me. I know it is very rare, but theoretically it is possible isn’t it? Is it possible to simply commit with conditions and throw exception in case the conditions are not fulfilled?
Any suggestion will be appreciated