mirror of
https://github.com/inventree/InvenTree.git
synced 2025-12-14 16:29:57 +00:00
[bug] Handle TransactionManagementError (#10942)
In the case where we try to call refresh_from_db within an atomic transaction block, it will throw a TransactionManagementError
This commit is contained in:
@@ -10,6 +10,7 @@ from django.core.exceptions import ValidationError
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import QuerySet
|
from django.db.models import QuerySet
|
||||||
from django.db.models.signals import post_save
|
from django.db.models.signals import post_save
|
||||||
|
from django.db.transaction import TransactionManagementError
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.urls import resolve, reverse
|
from django.urls import resolve, reverse
|
||||||
from django.urls.exceptions import NoReverseMatch
|
from django.urls.exceptions import NoReverseMatch
|
||||||
@@ -763,7 +764,15 @@ class InvenTreeTree(MPTTModel):
|
|||||||
|
|
||||||
if len(trees) > 0:
|
if len(trees) > 0:
|
||||||
# A tree update was performed, so we need to refresh the instance
|
# A tree update was performed, so we need to refresh the instance
|
||||||
|
try:
|
||||||
self.refresh_from_db()
|
self.refresh_from_db()
|
||||||
|
except TransactionManagementError:
|
||||||
|
# If we are inside a transaction block, we cannot refresh from db
|
||||||
|
pass
|
||||||
|
except Exception as e:
|
||||||
|
# Any other error is unexpected
|
||||||
|
InvenTree.sentry.report_exception(e)
|
||||||
|
InvenTree.exceptions.log_error(f'{self.__class__.__name__}.save')
|
||||||
|
|
||||||
def partial_rebuild(self, tree_id: int) -> bool:
|
def partial_rebuild(self, tree_id: int) -> bool:
|
||||||
"""Perform a partial rebuild of the tree structure.
|
"""Perform a partial rebuild of the tree structure.
|
||||||
|
|||||||
Reference in New Issue
Block a user