fix: prevent unnecessary db.commit for contact insert #45300
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We have ERPNext integrated with another system, when retrieving data from the other system, the following is created:
Customer
Addresses
Contacts
The link between the two systems has been created
When we synchronize, a for loop is performed and the customer, address and contact are inserted, but there may be errors in the process...
When there are errors, a rollback must be performed, but when inserting the contact, ERPNext executes an "after_insert" hook event calling the erpnext.telephony.doctype.call_log.call_log.link_existing_conversations method
thus executing frappe.db.commit()
Two improvements were made:
Only perform frappe.db.commit if there is an impact record returned by the select above.
Created an "ignore_auto_link_call_log" flag to ignore this method when we do not want it to execute, as this commit may break the code.