Changes between Initial Version and Version 3 of Ticket #22947


Ignore:
Timestamp:
Jul 4, 2014, 12:35:55 AM (10 years ago)
Author:
Aymeric Augustin
Comment:

There's at least one problem with your example: the method you're decorating with transaction.non_atomic_requests isn't a Django view (i.e. a callable that accepts a request and returns a response).

I've converted into a working test case, and that test passes under MySQL.

from django.contrib.auth.models import User
from django.db import transaction
from django.test import TransactionTestCase

class Ticket22947Test(TransactionTestCase):

    available_apps = ['django.contrib.auth', 'blabla']

    def test_ticket_22947(self):
        self.assertEqual(0, User.objects.count())
        array = [[[['John', 20], ['Bob', 30], ['Mark', 'not number']]]]
        transaction.set_autocommit(False)
        for item in array:
            try:
                user = User()
                user.name = item[0]
                user.age = item[1]
                user.save()
            except:
                transaction.rollback()
        transaction.commit()
        transaction.set_autocommit(True)
        self.assertEqual(0, User.objects.count())

Please see TicketClosingReasons/UseSupportChannels for further help on this issue.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #22947

    • Property Component Python 2Database layer (models, ORM)
    • Property Resolutioninvalid
    • Property Status newclosed
    • Property UI/UX unset
  • Ticket #22947 – Description

    initial v3  
    22my model: User (id: integer auto increment, name: string, age: integer)
    33I have a array data insert to database (database is mysql)
     4
     5{{{
    46[[[['John', 20], ['Bob', 30], ['Mark', 'not number']]]]
     7}}}
    58
    6 
     9{{{
    710@transaction.non_atomic_requests()
    811def update_Ac_Point_Detail(self):
     
    1922          return
    2023   transaction.commit()
    21 
     24}}}
    2225
    2326When I check in database, it has 2 new records. it's not rollback.
Back to Top