Saturday, July 6, 2013

Managing transactions using multiple databases

Hello,

During the design of a project, I came across a situation where I will have 2 databases.

Dealing with transactions even when having multiple databases is also trivial, simply select which one the transaction is about.

At a given point, I'll have to interact with both databases in the same view.
Consider the snippet below as an example (not tested, nor this is what I intend to do):

@transaction.commit_manually()  # using='db1' or using='db2' or none??
def my_view(request):
    try:
        obj1 = MyObject1()
        obj1.data = request.POST.get('data')
        obj1.save(using='db1')
        obj2 = MyObject2()
        obj2.obj1_id = obj1id
        obj2.save(using='db2')
    except:
        transaction.rollback()
    else:
        transaction.commit()
    ...


I didn't find any mention in the docs or in this list related to this, so here is my question:

How can I do a transaction management in both databases at the same time? Is that even possible?


Thanks in advance for your help.
Leandro.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate