From 0648bbc94d2058b7e2b563530f09593d621c254a Mon Sep 17 00:00:00 2001 From: Fabian Sinz Date: Mon, 7 Dec 2015 10:55:49 -0600 Subject: [PATCH 1/4] add new substance --- datajoint/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datajoint/connection.py b/datajoint/connection.py index d1bebdafa..bc116c8ce 100644 --- a/datajoint/connection.py +++ b/datajoint/connection.py @@ -59,7 +59,7 @@ def __init__(self, host, user, passwd, init_fun=None): port = int(port) else: port = config['database.port'] - self.conn_info = dict(host=host, port=port, user=user, passwd=passwd) + self.conn_info = dict(host=host, port=port, user=user, passwd=passwd, max_allowed_packet=1024**3) # 1073741824 self._conn = client.connect(init_command=init_fun, **self.conn_info) if self.is_connected: logger.info("Connected {user}@{host}:{port}".format(**self.conn_info)) From b46cd051480438d6c0552f6d089e49b30ed0a5d3 Mon Sep 17 00:00:00 2001 From: Fabian Sinz Date: Tue, 29 Dec 2015 10:08:07 -0600 Subject: [PATCH 2/4] transaction context manager checks for transaction --- datajoint/connection.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/datajoint/connection.py b/datajoint/connection.py index bc116c8ce..eb414a5ac 100644 --- a/datajoint/connection.py +++ b/datajoint/connection.py @@ -161,19 +161,21 @@ def commit_transaction(self): def transaction(self): """ Context manager for transactions. Opens an transaction and closes it after the with statement. - If an error is caught during the transaction, the commits are automatically rolled back. All - errors are raised again. + Only starts a transaction if there is not one going on already (MySQL does not support nested + transactions). If an error is caught during the transaction, the commits are automatically + rolled back. All errors are raised again. Example: >>> import datajoint as dj >>> with dj.conn().transaction as conn: >>> # transaction is open here """ - try: - self.start_transaction() - yield self - except: - self.cancel_transaction() - raise - else: - self.commit_transaction() + if not self.in_transaction: + try: + self.start_transaction() + yield self + except: + self.cancel_transaction() + raise + else: + self.commit_transaction() From 630694881f90284fb57cc6f67afae9037a7359e6 Mon Sep 17 00:00:00 2001 From: Fabian Sinz Date: Tue, 29 Dec 2015 10:16:40 -0600 Subject: [PATCH 3/4] small bugfix in transaction context manager --- datajoint/connection.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/datajoint/connection.py b/datajoint/connection.py index eb414a5ac..c876859ca 100644 --- a/datajoint/connection.py +++ b/datajoint/connection.py @@ -179,3 +179,5 @@ def transaction(self): raise else: self.commit_transaction() + else: + yield self From a92924b820d6f1f942e0cc35578a169f0351107f Mon Sep 17 00:00:00 2001 From: Fabian Sinz Date: Tue, 29 Dec 2015 10:24:49 -0600 Subject: [PATCH 4/4] transaction context manager now throws a waring if in transaction already --- datajoint/connection.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/datajoint/connection.py b/datajoint/connection.py index c876859ca..827de8acd 100644 --- a/datajoint/connection.py +++ b/datajoint/connection.py @@ -2,7 +2,7 @@ This module hosts the Connection class that manages the connection to the mysql database, and the `conn` function that provides access to a persistent connection in datajoint. """ - +import warnings from contextlib import contextmanager import pymysql as client import logging @@ -180,4 +180,6 @@ def transaction(self): else: self.commit_transaction() else: + warnings.warn("""Connection is in a transaction already. MySQL does not support nested transaction. This + transaction call will be ignored. """) yield self