#18080: @transaction.commit_manually plus context processors doesn't work well
-------------------------------+--------------------
     Reporter:  jstpierre@…    |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  Uncategorized  |    Version:  1.3
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 Imagine a view that looks like this:

 {{{
     @transaction.commit_manually
     def create_new_foo(request):
         name = request.GET['name']
         obj = MyFoo(name=name)
         # We need to add the object to a ManyToMany
         # so we need a PK.
         obj.save()
         add_to_many_to_many(obj)
         if obj.is_valid():
             valid = True
             transaction.commit()
         else:
             valid = False
             transaction.rollback()

         return render_to_response("objs/obj_created.html", {'valid':
 valid,
                                                             'obj': obj})
 }}}

 Now imagine a context processor in another application entirely that looks
 like this:

 {{{
     def num_my_bars(request):
         return MyBar.objects.count()
 }}}

 Since num_my_bars hits the database during the render, the transaction
 will be dirtied and leaving the commit_manually view will fail. A dirty
 solution may be to do:

 {{{
         response = render_to_response(...)
         transaction.set_clean()
         return response
 }}}

 in the view, but this is dirty and awkward.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18080>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to