Created
March 10, 2025 14:16
-
-
Save faniska/53cd2117bacbc193cdc0e74232133ef3 to your computer and use it in GitHub Desktop.
Odoo - emulate SERIALIZATION_FAILURE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
import time | |
def transaction_1(): | |
env = self.env(context={'active_test': False}) | |
with env.registry.cursor() as cr: | |
env1 = self.env(cr=cr) | |
lines = env1['account.bank.statement.line'].browse(st_lines.ids) | |
lines.write({'field_name': 'value'}) | |
time.sleep(2) # Simulate delay to overlap with transaction_2 | |
def transaction_2(): | |
env = self.env(context={'active_test': False}) | |
with env.registry.cursor() as cr: | |
env2 = self.env(cr=cr) | |
lines = env2['account.bank.statement.line'].browse(st_lines.ids) | |
lines.write({'field_name': 'value'}) | |
t1 = threading.Thread(target=transaction_1) | |
t2 = threading.Thread(target=transaction_2) | |
t1.start() | |
t2.start() | |
t1.join() | |
t2.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment