2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-03-11 22:54:17 +00:00

fix: wrap create_default_labels in transaction.atomic() savepoint to prevent PostgreSQL transaction abort (#11484)

When the plugin registry reloads during an active HTTP request, 
create_default_labels() raises ValidationError on duplicate template 
inserts. On PostgreSQL this aborts the entire outer atomic() block, 
causing TransactionManagementError on all stock operations in that request.

Fixes #11469

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
tigger2000ttfn
2026-03-11 07:21:03 -04:00
committed by GitHub
parent 27809d712a
commit a964d6682e

View File

@@ -7,6 +7,7 @@ from django.apps import AppConfig
from django.core.exceptions import AppRegistryNotReady, ValidationError from django.core.exceptions import AppRegistryNotReady, ValidationError
from django.core.files.base import ContentFile from django.core.files.base import ContentFile
from django.core.files.storage import default_storage from django.core.files.storage import default_storage
from django.db import transaction
from django.db.utils import IntegrityError, OperationalError, ProgrammingError from django.db.utils import IntegrityError, OperationalError, ProgrammingError
import structlog import structlog
@@ -160,9 +161,10 @@ class ReportConfig(AppConfig):
# Otherwise, create a new entry # Otherwise, create a new entry
try: try:
# Create a new entry # Create a new entry
report.models.LabelTemplate.objects.create( with transaction.atomic():
**template, template=self.file_from_template('label', filename) report.models.LabelTemplate.objects.create(
) **template, template=self.file_from_template('label', filename)
)
logger.info("Creating new label template: '%s'", template['name']) logger.info("Creating new label template: '%s'", template['name'])
except ValidationError: except ValidationError:
logger.warning( logger.warning(