P
P
pvgdrk2014-08-13 13:16:59
Django
pvgdrk, 2014-08-13 13:16:59

Do transactions work in a loop in Django?

There is a function processing the request. The application structure requires that writing to the database is carried out in a loop in a separate function:

def responseFunction(request):
    for el in request.POST['elements']:
        #...
        saveToDb(el)

def saveToDb(el):
    #...
    enrty.save()
    return HttpResponse()

Whether probably in that case to carry out all records in a cycle by transaction?
There is this line in settings.MIDDLEWARE_CLASSES: 'django.middleware.transaction.TransactionMiddleware', but the transaction does not work - if an error occurs in one of the iterations, the actions of the previous ones are not rolled back

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kazmiruk, 2014-08-13
@pvgdrk

Specify 'ATOMIC_REQUESTS': True in DBMS connection settings in jang and all your requests will turn into transactions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question