Opened 17 years ago

Closed 17 years ago

#6763 closed (invalid)

Transactions don't work as per the documentation

Reported by: KayEss Owned by: nobody
Component: Uncategorized Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The documentation here http://www.djangoproject.com/documentation/transactions/ 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 by KayEss, 17 years ago

Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top