mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-10 18:39:36 -06:00
atomic lock on both default and potentially branch database
This commit is contained in:
parent
5208e544ce
commit
aec8e293bf
@ -44,10 +44,18 @@ class ScriptJob(JobRunner):
|
||||
# A script can modify multiple models so need to do an atomic lock on
|
||||
# both the default database (for non ChangeLogged models) and potentially
|
||||
# any other database (for ChangeLogged models)
|
||||
with transaction.atomic(using=router.db_for_write(Device)):
|
||||
script.output = script.run(data, commit)
|
||||
if not commit:
|
||||
raise AbortTransaction()
|
||||
branch_db = router.db_for_write(Device)
|
||||
with transaction.atomic(using='default'):
|
||||
# If branch database is different from default, wrap in a second atomic transaction
|
||||
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:
|
||||
script.log_info(message=_("Database changes have been reverted automatically."))
|
||||
if script.failed:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user