19644 Make atomic use correct database instead of default (#19651)

* 19644 set atomic transactions to appropriate database

* 19644 set atomic transactions for Job Script run

* 19644 set atomic transactions to appropriate database

* 19644 set atomic transactions to appropriate database

* 19644 fix review comments

* 19644 fix review comments
This commit is contained in:
Arthur Hanson
2025-06-25 12:00:26 -07:00
committed by GitHub
parent f97d07a11c
commit a17699d261
11 changed files with 44 additions and 41 deletions

View File

@@ -1,6 +1,6 @@
from django.contrib import messages
from django.contrib.contenttypes.models import ContentType
from django.db import transaction
from django.db import router, transaction
from django.db.models import Prefetch, Sum
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
@@ -297,7 +297,7 @@ class ClusterAddDevicesView(generic.ObjectEditView):
if form.is_valid():
device_pks = form.cleaned_data['devices']
with transaction.atomic():
with transaction.atomic(using=router.db_for_write(Device)):
# Assign the selected Devices to the Cluster
for device in Device.objects.filter(pk__in=device_pks):
@@ -332,7 +332,7 @@ class ClusterRemoveDevicesView(generic.ObjectEditView):
if form.is_valid():
device_pks = form.cleaned_data['pk']
with transaction.atomic():
with transaction.atomic(using=router.db_for_write(Device)):
# Remove the selected Devices from the Cluster
for device in Device.objects.filter(pk__in=device_pks):