Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#14550 closed (fixed)

commit_on_success no longer sets back to autocommit mode

Reported by: Florian Apolloner Owned by: nobody
Component: Database layer (models, ORM) 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

commit_on_success doesn't reset to the autocommit transaction state since r14288. If I understand the new decorator/context_manager code correctly we will need a leave_transaction_management in commit_on_success.exiting.

Change History (3)

comment:1 by jbronn, 14 years ago

Here's how to reproduce. Create an application, and place the following in models.py:

from django.db import models

class Oblast(models.Model):
    """
    Represents an Ukranian administrative region, or Oblast.
    """
    ua_name = models.CharField(max_length=50)
    en_name = models.CharField(max_length=50)

    def __unicode__(self):
        return u'%s (%s)' % (self.ua_name, self.en_name)

Then, create a module in the application called load.py, and insert the following:

from django.db import transaction
from models import Oblast

oblasts = [
    (u'Kiev', u'\u041a\u0438\u0457\u0432\u0441\u044c\u043a\u0430'),
]


@transaction.commit_on_success
def init_oblasts():
    for en_name, ua_name in oblasts:
        ob = Oblast(en_name=en_name)
        ob.save()
    
def run():
    
    init_oblasts()

    for en_name, ua_name in oblasts:
        ob = Oblast.objects.get(en_name=en_name)
        ob.ua_name = ua_name
        ob.save()
    
    print transaction.is_dirty()

Assuming the code is inside an application entitled ukraine, and the database synced, then follow the below instructions:

  1. ./manage.py shell
  1. from ukraine import load; load.run()
  1. Exit the shell
  1. ./manage.py shell and query the database. The ua_name field is not set because the transaction was not committed. This does not happen in 1.2.X.

comment:2 by Alex Gaynor, 14 years ago

Resolution: fixed
Status: newclosed

Fixed in [14343].

comment:3 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

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