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