Commit 1f0f815b authored by Georgios D. Tsoukalas's avatar Georgios D. Tsoukalas Committed by Sofia Papagiannaki
Browse files

fix trasactionless query in pithos backend init

The query was submitted for execution without any prior transaction
setup, which caused:

1. psycopg2 to implicitly start a transaction
2. the new transaction to remain unknown to the sqlalchemy layer
   since it was implicit
3. the pooling cleanup to think that the connection was clean
4. the backend to be pooled with a transaction active

Refs: #3580
parent ee6f0a62
......@@ -37,8 +37,10 @@ class DBWorker(object):
def __init__(self, **params):
self.params = params
self.conn = params['wrapper'].conn
self.engine = params['wrapper'].engine
wrapper = params['wrapper']
self.wrapper = wrapper
self.conn = wrapper.conn
self.engine = wrapper.engine
def escape_like(self, s):
return s.replace('\\', '\\\\').replace('%', '\%').replace('_', '\_')
......@@ -206,13 +206,18 @@ class Node(DBWorker):
s = self.nodes.select().where(and_(self.nodes.c.node == ROOTNODE,
self.nodes.c.parent == ROOTNODE))
rp = self.conn.execute(s)
r = rp.fetchone()
rp.close()
if not r:
s = self.nodes.insert(
).values(node=ROOTNODE, parent=ROOTNODE, path='')
self.conn.execute(s)
wrapper = self.wrapper
wrapper.execute()
try:
rp = self.conn.execute(s)
r = rp.fetchone()
rp.close()
if not r:
s = self.nodes.insert(
).values(node=ROOTNODE, parent=ROOTNODE, path='')
self.conn.execute(s)
finally:
wrapper.commit()
def node_create(self, parent, path):
"""Create a new node from the given properties.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment