mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-12 03:19:36 -06:00
atomic lock on both default and potentially branch database
This commit is contained in:
parent
5208e544ce
commit
aec8e293bf
@ -44,7 +44,15 @@ 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)
|
||||||
|
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)
|
script.output = script.run(data, commit)
|
||||||
if not commit:
|
if not commit:
|
||||||
raise AbortTransaction()
|
raise AbortTransaction()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user