Skip to content
Snippets Groups Projects
Commit 8a02a625 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

Got rid of decorator for transaction

parent 6d505ef2
No related branches found
No related tags found
No related merge requests found
# v2.20.4
* removed the decorator syntax for transaction, it's confusing and contrary to Zen of Python
\ No newline at end of file
__version__ = '2.20.4a1'
__version__ = '2.20.4a2'
......@@ -19,13 +19,6 @@ class transaction:
Leaving the context manager will automatically close the cursor for you.
>>> def conn_getter_function() -> connection:
>>> ....
>>> @transaction(conn_getter_function)
>>> ....
The same syntax can be used, if you session depends eg. on a thread.
:param connection_or_getter: the connection object to use, or a callable/0, that called with
this thread will provide us with a connection
:param close_the_connection_after: whether the connection should be closed after use
......@@ -38,19 +31,6 @@ class transaction:
self.cursor = None
self.log_exception = log_exception
def __call__(self, fun):
@wraps(fun)
def inner(*args, **kwargs):
with self as cur:
if fun.__name__ == fun.__qualname__:
return fun(cur, *args, **kwargs)
else:
if not len(args):
return fun(*args)
else:
return fun(*args[0], cur, *args[1:], **kwargs)
return inner
def __enter__(self):
self.cursor = self.connection.cursor()
return self.cursor
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment