Commit a6002ca6 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[external storage] refactor to give session to storage's callback (needed by vcsfile storage)

--HG--
branch : stable
parent 865c1779cc84
......@@ -452,8 +452,7 @@ class NativeSQLSource(SQLAdapterMixIn, AbstractSource):
cursor = self.doexec(session, sql, args)
else:
raise
results = self.process_result(cursor, cbs)
results = self.process_result(cursor, cbs, session=session)
assert dbg_results(results)
return results
......
......@@ -33,10 +33,10 @@ class Storage(object):
"""abstract storage
* If `source_callback` is true (by default), the callback will be run during
query result process of fetched attribute's valu and should have the
query result process of fetched attribute's value and should have the
following prototype::
callback(self, source, value)
callback(self, source, session, value)
where `value` is the value actually stored in the backend. None values
will be skipped (eg callback won't be called).
......@@ -99,7 +99,7 @@ class BytesFileSystemStorage(Storage):
self.default_directory = defaultdir
self.fsencoding = fsencoding
def callback(self, source, value):
def callback(self, source, session, value):
"""sql generator callback when some attribute with a custom storage is
accessed
"""
......
......@@ -202,7 +202,7 @@ class SQLAdapterMixIn(object):
return newargs
return query_args
def process_result(self, cursor, column_callbacks=None):
def process_result(self, cursor, column_callbacks=None, session=None):
"""return a list of CubicWeb compliant values from data in the given cursor
"""
# use two different implementations to avoid paying the price of
......@@ -210,9 +210,10 @@ class SQLAdapterMixIn(object):
# lookup
if not column_callbacks:
return self._process_result(cursor)
return self._cb_process_result(cursor, column_callbacks)
assert session
return self._cb_process_result(cursor, column_callbacks, session)
def _process_result(self, cursor, column_callbacks=None):
def _process_result(self, cursor):
# begin bind to locals for optimization
descr = cursor.description
encoding = self._dbencoding
......@@ -230,7 +231,7 @@ class SQLAdapterMixIn(object):
results[i] = result
return results
def _cb_process_result(self, cursor, column_callbacks):
def _cb_process_result(self, cursor, column_callbacks, session):
# begin bind to locals for optimization
descr = cursor.description
encoding = self._dbencoding
......@@ -249,7 +250,7 @@ class SQLAdapterMixIn(object):
value = process_value(value, descr[col], encoding, binary)
else:
for cb in cbstack:
value = cb(self, value)
value = cb(self, session, value)
result.append(value)
results[i] = result
return results
......
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