Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django1.6 transaction.atomic questions

I just switched to Django 1.6 (with Posgres 9.1) and there is a few questions that I couldn't answer myself:

  1. (Answered) Is there a statement that prints/shows me if I am currently inside one or more and in which transaction.atomic blocks?

  2. (Answered) I neither have TransactionMiddleware enabled nor set ATOMIC_REQUESTS to True. So per default my code is not wrapped inside a transaction.atomic block, correct?

  3. Are sql statements that are executed via cursor committed properly when executed inside a transaction.atomic block? Is there another/better way to commit them?

    with transaction.atomic():
        cursor = connection.cursor()
        cursor.execute(sql)
    
  4. Do I need to wrap cursor.executemany() in a transaction.atomic block or does the execution already happen atomically?

  5. How can I see the current autocommit status? When is the status set, at the beginning of a connection, a transaction, as global database setting?

like image 618
kev Avatar asked Oct 21 '22 14:10

kev


1 Answers

To answer one of your questions:

You can find out if you are currently in an atomic block using the connection object returned from:

from django.db.transaction import get_connection or any of the connection objects inside of django.db.connections

which has an in_atomic_block property.


I feel like its going to be easiest just to look through the django source

like image 125
dm03514 Avatar answered Oct 24 '22 01:10

dm03514