2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-12-20 11:13:28 +00:00

[bug] Handle TransactionManagementError (#10942) (#10943)

In the case where we try to call refresh_from_db within an atomic transaction block, it will throw a TransactionManagementError

(cherry picked from commit 38b27271ac)

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
github-actions[bot]
2025-12-02 17:23:09 +11:00
committed by GitHub
parent f39b3190e3
commit 10769ccb04

View File

@@ -9,6 +9,7 @@ from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import QuerySet
from django.db.models.signals import post_save
from django.db.transaction import TransactionManagementError
from django.dispatch import receiver
from django.urls import resolve, reverse
from django.urls.exceptions import NoReverseMatch
@@ -757,7 +758,15 @@ class InvenTreeTree(MPTTModel):
if len(trees) > 0:
# A tree update was performed, so we need to refresh the instance
try:
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:
"""Perform a partial rebuild of the tree structure.