atomic lock on both default and potentially branch database
Some checks failed
CI / build (20.x, 3.10) (push) Has been cancelled
CI / build (20.x, 3.11) (push) Has been cancelled
CI / build (20.x, 3.12) (push) Has been cancelled

This commit is contained in:
Arthur 2025-12-01 11:14:06 -08:00
parent 5208e544ce
commit aec8e293bf

View File

@ -44,10 +44,18 @@ class ScriptJob(JobRunner):
# A script can modify multiple models so need to do an atomic lock on # A script can modify multiple models so need to do an atomic lock on
# both the default database (for non ChangeLogged models) and potentially # both the default database (for non ChangeLogged models) and potentially
# any other database (for ChangeLogged models) # any other database (for ChangeLogged models)
with transaction.atomic(using=router.db_for_write(Device)): branch_db = router.db_for_write(Device)
script.output = script.run(data, commit) with transaction.atomic(using='default'):
if not commit: # If branch database is different from default, wrap in a second atomic transaction
raise AbortTransaction() if branch_db != 'default':
with transaction.atomic(using=branch_db):
script.output = script.run(data, commit)
if not commit:
raise AbortTransaction()
else:
script.output = script.run(data, commit)
if not commit:
raise AbortTransaction()
except AbortTransaction: except AbortTransaction:
script.log_info(message=_("Database changes have been reverted automatically.")) script.log_info(message=_("Database changes have been reverted automatically."))
if script.failed: if script.failed: