Changes between Initial Version and Version 1 of Ticket #26043, comment 4


Ignore:
Timestamp:
Jan 6, 2016, 11:42:07 AM (9 years ago)
Author:
Sven R. Kunze

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #26043, comment 4

    initial v1  
    11> I believe the transaction created by ATOMIC_REQUESTS only applies to the view, not to middleware.
    22
    3 Exactly. That's why we monkey patched {{{ BaseHandler.make_view_atomic }}}.
     3Exactly. That's why we monkey patched [https://github.com/django/django/blob/16411b8400ad08f90c236bb2e18f65c655f903f8/django/core/handlers/base.py#L78|{{{ BaseHandler.make_view_atomic].
     4
     5
     6Basically like this:
     7{{{
     8def make_view_atomic(self, view):
     9    non_atomic_requests = getattr(view, '_non_atomic_requests', set())
     10    for db in connections.all():
     11        if (db.settings_dict['ATOMIC_REQUESTS']
     12                and db.alias not in non_atomic_requests):
     13            view = transaction.atomic(using=db.alias)(yet_another_wrapper(view))
     14    return view
     15
     16def yet_another_wrapper(view):
     17    def wrapped_view(request, *args, **kwargs):
     18        # do what legacy systems usually do
     19        # weird stuff
     20        # custom things
     21        return view(request, *args, **kwargs)
     22    return wrapped_view
     23}}}
Back to Top