编辑django-cms页面时的TransactionManagementError

时间:2014-07-14 02:01:56

标签: python django sqlite atomic django-cms

我正要问一个问题并在发布之前找到解决方案:)

问题:

我正在尝试为一个简单的应用设置django-cms,并且在尝试编辑前端页面时收到了TransactionManagementError

django.db.transaction.TransactionManagementError
TransactionManagementError: This is forbidden when an 'atomic' block is active.

我目前正在使用sqlite,我需要添加'ATOMIC_REQUESTS': True因为我得到了这个:

TransactionManagementError: Your database backend doesn't behave properly when autocommit is off. Turn it on before using 'atomic'.

数据库设置

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        'ATOMIC_REQUESTS': True
    }
}

我正在使用的版本

Django==1.6.5
django-cms==3.0.2

这是我得到的追溯:

django.db.transaction.TransactionManagementError
TransactionManagementError: This is forbidden when an 'atomic' block is active.

Traceback (most recent call last)
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 67, in __call__
return self.application(environ, start_response)
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 206, in __call__
response = self.get_response(request)
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django/core/handlers/base.py", line 194, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django/core/handlers/base.py", line 229, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django_extensions/management/technical_response.py", line 5, in null_technical_500_response
six.reraise(exc_type, exc_value, tb)
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django/core/handlers/base.py", line 112, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django/db/transaction.py", line 371, in inner
return func(*args, **kwargs)
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/cms/admin/settingsadmin.py", line 21, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django/utils/decorators.py", line 99, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django/views/decorators/cache.py", line 52, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 198, in inner
return view(request, *args, **kwargs)
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django/utils/decorators.py", line 29, in _wrapper
return bound_func(*args, **kwargs)
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django/utils/decorators.py", line 99, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django/utils/decorators.py", line 25, in bound_func
return func(self, *args2, **kwargs2)
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django/db/transaction.py", line 430, in inner
with self:
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django/db/transaction.py", line 422, in __enter__
self.entering(self.using)
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django/db/transaction.py", line 483, in entering
enter_transaction_management(using=using)
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django/db/transaction.py", line 70, in enter_transaction_management
get_connection(using).enter_transaction_management(managed, forced)
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django/db/backends/__init__.py", line 287, in enter_transaction_management
self.validate_no_atomic_block()
File "/Users/gableroux/.virtualenvs/adls-si/lib/python2.7/site-packages/django/db/backends/__init__.py", line 367, in validate_no_atomic_block
"This is forbidden when an 'atomic' block is active.")
TransactionManagementError: This is forbidden when an 'atomic' block is active.
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.

1 个答案:

答案 0 :(得分:2)

我只需要从django-cms==3.0.2更新到django-cms==3.0.3,问题就不复存在了。这可以帮助别人。

我不确定究竟是什么问题。我也得到了<class 'cms.models.titlemodels.Title'> has not been registered with django-reversion的版本,See this issue,升级到3.0.3似乎也解决了这个问题。