Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#14550 closed (fixed)

commit_on_success no longer sets back to autocommit mode

Reported by: apollo13 Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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.

Attachments (0)

Change History (3)

comment:1 Changed 3 years ago by jbronn

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 3 years ago by Alex

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in [14343].

comment:3 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.