Я пытаюсь изменить одно из полей записи перед удалением:
query_item.txId = txId
try:
query_item.delete()
except Exception as e:
print(str(e))
Дело в том, что написанный выше код вызывает исключение:
Произошла ошибка втекущая транзакция.Вы не можете выполнять запросы до конца атомарного блока.
Я пытался поиграть с оператором
with transaction.atomic():
, но это ничего не изменило.
Более того, следующая комбинация:
query_item.txId = txId
query_item.save()
try:
query_item.delete()
except Exception as e:
print(str(e))
по-прежнему вызывает ту же ошибку
@ edit
во всем проекте, на который указывает только один сигналзаписи, принадлежащие модели query_item:
pre_delete.connect(create_receipts, sender=itemToPurchase)
@ edit2
Это определенно что-то не так с сигналом pre_delete
Я просто удалил его, и тест прошел гладко ихорошо.
В любом случае, когда я использую вышеприведенный сигнал и удаляю все операторы try-кроме, я получаю следующий журнал ошибок:
Traceback (most recent call last):
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "User/env/lib/python3.7/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "User/env/lib/python3.7/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 74, in inner
return func(*args, **kwds)
File "User/env/lib/python3.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "User/env/lib/python3.7/site-packages/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "User/profilespaidbybtc/payment_realizer/views.py", line 240, in post
query_item.delete()
File "User/env/lib/python3.7/site-packages/django/db/models/base.py", line 880, in delete
return collector.delete()
File "User/env/lib/python3.7/site-packages/django/db/models/deletion.py", line 277, in delete
sender=model, instance=obj, using=self.using
File "User/env/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 175, in send
for receiver in self._live_receivers(sender)
File "User/env/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 175, in <listcomp>
for receiver in self._live_receivers(sender)
File "User/profilespaidbybtc/receipt/models.py", line 186, in create_receipts
'token': hash_generator_token.make_token(instance_receiptModel)
File "User/env/lib/python3.7/site-packages/django/template/loader.py", line 61, in render_to_string
template = get_template(template_name, using=using)
File "User/env/lib/python3.7/site-packages/django/template/loader.py", line 15, in get_template
return engine.get_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/backends/django.py", line 34, in get_template
return Template(self.engine.get_template(template_name), self)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 144, in get_template
template, origin = self.find_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 124, in find_template
for loader in self.template_loaders:
File "User/env/lib/python3.7/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 98, in template_loaders
return self.get_template_loaders(self.loaders)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 103, in get_template_loaders
loader = self.find_template_loader(template_loader)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 116, in find_template_loader
loader_class = import_string(loader)
File "User/env/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "User/env/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'app_namespace'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "User/env/lib/python3.7/site-packages/django/utils/deprecation.py", line 91, in __call__
response = response or self.get_response(request)
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 129, in handle_uncaught_exception
return callback(request, **param_dict)
File "User/env/lib/python3.7/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "User/env/lib/python3.7/site-packages/django/views/defaults.py", line 69, in server_error
template = loader.get_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/loader.py", line 15, in get_template
return engine.get_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/backends/django.py", line 34, in get_template
return Template(self.engine.get_template(template_name), self)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 144, in get_template
template, origin = self.find_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 124, in find_template
for loader in self.template_loaders:
File "User/env/lib/python3.7/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 98, in template_loaders
return self.get_template_loaders(self.loaders)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 103, in get_template_loaders
loader = self.find_template_loader(template_loader)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 116, in find_template_loader
loader_class = import_string(loader)
File "User/env/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "User/env/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'app_namespace'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "User/env/lib/python3.7/site-packages/django/utils/deprecation.py", line 91, in __call__
response = response or self.get_response(request)
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 129, in handle_uncaught_exception
return callback(request, **param_dict)
File "User/env/lib/python3.7/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "User/env/lib/python3.7/site-packages/django/views/defaults.py", line 69, in server_error
template = loader.get_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/loader.py", line 15, in get_template
return engine.get_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/backends/django.py", line 34, in get_template
return Template(self.engine.get_template(template_name), self)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 144, in get_template
template, origin = self.find_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 124, in find_template
for loader in self.template_loaders:
File "User/env/lib/python3.7/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 98, in template_loaders
return self.get_template_loaders(self.loaders)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 103, in get_template_loaders
loader = self.find_template_loader(template_loader)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 116, in find_template_loader
loader_class = import_string(loader)
File "User/env/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "User/env/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'app_namespace'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "User/env/lib/python3.7/site-packages/django/utils/deprecation.py", line 91, in __call__
response = response or self.get_response(request)
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 129, in handle_uncaught_exception
return callback(request, **param_dict)
File "User/env/lib/python3.7/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "User/env/lib/python3.7/site-packages/django/views/defaults.py", line 69, in server_error
template = loader.get_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/loader.py", line 15, in get_template
return engine.get_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/backends/django.py", line 34, in get_template
return Template(self.engine.get_template(template_name), self)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 144, in get_template
template, origin = self.find_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 124, in find_template
for loader in self.template_loaders:
File "User/env/lib/python3.7/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 98, in template_loaders
return self.get_template_loaders(self.loaders)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 103, in get_template_loaders
loader = self.find_template_loader(template_loader)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 116, in find_template_loader
loader_class = import_string(loader)
File "User/env/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "User/env/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'app_namespace'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "User/env/lib/python3.7/site-packages/django/utils/deprecation.py", line 91, in __call__
response = response or self.get_response(request)
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 129, in handle_uncaught_exception
return callback(request, **param_dict)
File "User/env/lib/python3.7/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "User/env/lib/python3.7/site-packages/django/views/defaults.py", line 69, in server_error
template = loader.get_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/loader.py", line 15, in get_template
return engine.get_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/backends/django.py", line 34, in get_template
return Template(self.engine.get_template(template_name), self)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 144, in get_template
template, origin = self.find_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 124, in find_template
for loader in self.template_loaders:
File "User/env/lib/python3.7/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 98, in template_loaders
return self.get_template_loaders(self.loaders)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 103, in get_template_loaders
loader = self.find_template_loader(template_loader)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 116, in find_template_loader
loader_class = import_string(loader)
File "User/env/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "User/env/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'app_namespace'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "User/env/lib/python3.7/site-packages/django/utils/deprecation.py", line 91, in __call__
response = response or self.get_response(request)
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 129, in handle_uncaught_exception
return callback(request, **param_dict)
File "User/env/lib/python3.7/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "User/env/lib/python3.7/site-packages/django/views/defaults.py", line 69, in server_error
template = loader.get_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/loader.py", line 15, in get_template
return engine.get_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/backends/django.py", line 34, in get_template
return Template(self.engine.get_template(template_name), self)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 144, in get_template
template, origin = self.find_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 124, in find_template
for loader in self.template_loaders:
File "User/env/lib/python3.7/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 98, in template_loaders
return self.get_template_loaders(self.loaders)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 103, in get_template_loaders
loader = self.find_template_loader(template_loader)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 116, in find_template_loader
loader_class = import_string(loader)
File "User/env/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "User/env/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'app_namespace'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "User/env/lib/python3.7/site-packages/django/utils/deprecation.py", line 91, in __call__
response = response or self.get_response(request)
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "User/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 129, in handle_uncaught_exception
return callback(request, **param_dict)
File "User/env/lib/python3.7/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "User/env/lib/python3.7/site-packages/django/views/defaults.py", line 69, in server_error
template = loader.get_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/loader.py", line 15, in get_template
return engine.get_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/backends/django.py", line 34, in get_template
return Template(self.engine.get_template(template_name), self)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 144, in get_template
template, origin = self.find_template(template_name)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 124, in find_template
for loader in self.template_loaders:
File "User/env/lib/python3.7/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 98, in template_loaders
return self.get_template_loaders(self.loaders)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 103, in get_template_loaders
loader = self.find_template_loader(template_loader)
File "User/env/lib/python3.7/site-packages/django/template/engine.py", line 116, in find_template_loader
loader_class = import_string(loader)
File "User/env/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "User/env/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'app_namespace'
During handling of the above exception, another exception occurred: