text: Opened 8 years ago
  Closed 8 years ago
  #6763 closed (invalid)
  Transactions don't work as per the documentation
  Description
  The documentation here describes features of the transaction management, but there appears to be a fault which causes transactions not be managed correctly.
  The following code should result in no database changes (the type of object created is not important - it can be anything).
  from django.db import transaction from django.http import HttpResponseRedirect from bmf.core.models import * @transaction.commit_on_success def company_fail(request): ct = CompanyType() ct.name = "Charity" ct.save() raise ValueError, 'Do not carry this out'
  Executed as a view it raises an error page as expected, but the new CompanyType instance is still added to the database.
  Using postgres 8.3 & psycopg 2-2.0.6 on Windows.
  Change History (1)
  comment:1 Changed 8 years ago by KayEss
  - Needs documentation unset
  - Needs tests unset
  - Patch needs improvement unset
  - Resolution set to invalid
  - Status changed from new to closed
  We've tracked this down to the way that Postgres reports table statistics on some platforms/builds. An aborted transaction still counts the inserts so table statistics show more rows inserted than are in the table. The rolled back inserts are not counted as deletions so the row counts appear larger than they really are.
  There does appear to be something up with commit_on_success, but we haven't managed to isolate that problem fully. Sometimes it seems to require an explicit rollback in order for the connection to continue to work. We'll file a separate ticket when we work it out.