django-cms / django-cms

The easy-to-use and developer-friendly enterprise CMS powered by Django
http://www.django-cms.org
BSD 3-Clause "New" or "Revised" License
10.16k stars 3.1k forks source link

When using TransactionMiddleware, page is still added on exception #751

Closed mitar closed 13 years ago

mitar commented 13 years ago

With current develop branch (199d1a2c5b68a5b8eab2e1cdced452b24d8186b8) when using TransactionMiddleware (listed as last in MIDDLEWARE_CLASSES), page is still added when adding through admin, when exception is raised. For example I get this stacktrace, but page is added:

Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py", line 280, in run
    self.result = application(self.environ, self.start_response)
  File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py", line 674, in __call__
    return self.application(environ, start_response)
  File "/usr/lib/pymodules/python2.6/django/core/handlers/wsgi.py", line 245, in __call__
    response = middleware_method(request, response)
  File "/usr/lib/pymodules/python2.6/django/contrib/sessions/middleware.py", line 36, in process_response
    request.session.save()
  File "/usr/lib/pymodules/python2.6/django/contrib/sessions/backends/db.py", line 61, in save
    sid = transaction.savepoint(using=using)
  File "/usr/lib/pymodules/python2.6/django/db/transaction.py", line 229, in savepoint
    connection._savepoint(sid)
  File "/usr/lib/pymodules/python2.6/django/db/backends/__init__.py", line 56, in _savepoint
    self.cursor().execute(self.ops.savepoint_create_sql(sid))
  File "/usr/lib/pymodules/python2.6/django/db/backends/util.py", line 15, in execute
    return self.cursor.execute(sql, params)
  File "/usr/lib/pymodules/python2.6/django/db/backends/postgresql_psycopg2/base.py", line 44, in execute
    return self.cursor.execute(query, args)
DatabaseError: current transaction is aborted, commands ignored until end of transaction block  
[26/Mar/2011 23:22:09] "POST /admin/cms/page/add/?language=en& HTTP/1.1" 500 1408

Futhermore, page can be added with the same slug multiple times (for example just reloading the POST request multiple times on the exception above).

Hm, it seems it is the same with or without TransactionMiddleware.

I am also not sure why this exception is raised in the first place. So currently having almost the installation as described in the tutorial gives you such errors.

mitar commented 13 years ago

This is on Django 1.2.4.

It works normally with sqlite database. But not on PostgreSQL (8.4). TransactionMiddleware does not seem to have anything to do with that.

Pages with the same slug can still be added. And then there is an error when you want to save them, saying that there is a duplicate slug.

I think this it is not really necessary to prevent duplicated slugs, only published pages should not have the same slug. But sometimes it is OK to have unpublished pages prepared to swap them around.

chrisglass commented 13 years ago

Could you please test and confirm it still happens after https://github.com/divio/django-cms/commit/f49e929eac103c8c37005c5291d909c5f170d22c ?

mitar commented 13 years ago

No difference.

mitar commented 13 years ago

I am using also reversion. Maybe this is the cause?

mitar commented 13 years ago

Yes. This is it. I removed it from enabled Django applications and now it works correctly.

mitar commented 13 years ago

I am using d4bc1a368add0ad5b24e40f1695e82ee9b4d1742 version of django-reversion.

stephrdev commented 13 years ago

I can not reproduce this bug. I enabled the TransactionMiddleware, django-reversion and stuff. Adding pages just work and there are no transaction exceptions.

ojii commented 13 years ago

can't reproduce, closed until we have a test

mitar commented 13 years ago

You tested on PostgreSQL?

stephrdev commented 13 years ago

Tested sqlite, mysql and postres.

mitar commented 13 years ago

Hm. OK.