Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does django connection cursor auto commit after each .execute() query?

from django.db import connection

def executeQuery(query, params):
    cur=connection.cursor()
    cur.execute(query, params) // this is update query
    cur.close()

I have series of queries and I call this method for each query, but it looks like it rollbacks entire operation if any query (let's say 3rd query) gets failed.

I thought, after execute(), it immediately commit it and it does not depend on the next query.

Shouldn't django has auto commit feature?

like image 950
ronie Avatar asked Jan 15 '14 21:01

ronie


1 Answers

Database altering operations are automatically committed. However, if you are using the django.middleware.transaction.TransactionMiddleware or something similar, then they will be only committed if the page rendering finishes without any error, otherwise a rollback will happen.

For further details refer to the documentation for django 1.5 (the version used in the question). Check the latest documentation too.

like image 90
Vajk Hermecz Avatar answered Sep 20 '22 21:09

Vajk Hermecz