Задать вопрос

Тел: +7 965 3737 888

550

Просмотров

0

Ответов

nested transactions context manager and decorator

This is a modification of Django 1.3's transaction.commit_on_success() decorator and context manager. It's inspired by snippet 1343 which unfortunately don't work in current Django neither as a context manager.

In my junior projects it works fine but I've not tested in critical projects yet! YMMV !

How it works: it simply counts the nesting level and does the real transaction enter/exit only on first call and last call respectively (code copied from Django's commit_on_success() ). It use thread local storage to save the per-thread nesting level count safely.

To use it just put the code in a file (i.e. nested_commit_on_success.py) and import and use it exacly as normal commit_on_success(), both as decorator (@nested_commit_success) or context manager (with nested_commit_on_success(): ).

Any feedback is welcome!

Вопрос полезен? Да0/Нет0
file_2896.py(1.2Кб)
None