最近会遇到很多错误:
An error occurred in the current transaction. You can't " TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.
异常不在测试的上下文中(如在其他堆栈溢出问题中)。这些例外来自许多不同的观点,并且在一天中的某些时候也是如此。
我正在运行Django 1.7.1,Python 2.7,MySql 5.7(谷歌云托管)
它可能与Django数据库会话相关吗?
我在SessionStore.save()中看到这段代码(\ django \ contrib \ sessions \ backends \ db.py)
with transaction.atomic(using=using):
obj.save(force_insert=must_create, using=using)
会话保存是否会导致其他请求返回TransactionManagementError
这是完整的堆栈跟踪:
Traceback (most recent call last): File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 57, in wrapped_view return view_func(*args, **kwargs) File "/opt/webapps/app/reports/api.py", line 573, in track_album_played albumStore = AlbumStore.objects.only('id').get(id=album_store_id) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/django/db/models/query.py", line 351, in get num = len(clone) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/django/db/models/query.py", line 122, in __len__ self._fetch_all() File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/django/db/models/query.py", line 966, in _fetch_all self._result_cache = list(self.iterator()) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/django/db/models/query.py", line 265, in iterator for row in compiler.results_iter(): File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 700, in results_iter for rows in self.execute_sql(MULTI): File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql cursor.execute(sql, params) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/django/db/backends/utils.py", line 59, in execute self.db.validate_no_broken_transaction() File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/django/db/backends/__init__.py", line 386, in validate_no_broken_transaction "An error occurred in the current transaction. You can't " TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.
报告/ api.py:560
@csrf_exempt def track_album_played(request): album_store_id= request.REQUEST.get('album_store_id') album_origin_id= request.REQUEST.get('album_origin_id') bundle_id= request.GET.get('bundle_id') albumStore = None if(album_store_id): album_store_id=album_store_id.replace('?','') try: albumStore = AlbumStore.objects.only('id').get(id=album_store_id)