Merge pull request #18 from Eficent/11.0-fix-base_external_dbsource_sqlite

[11.0][FIX] base_external_dbsource_sqlite crashing when sqlparams equal None
This commit is contained in:
Jordi Ballester Alomar
2018-11-30 17:59:20 +01:00
committed by GitHub
3 changed files with 14 additions and 2 deletions

View File

@@ -3,7 +3,7 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
{ {
'name': 'External Database Source - SQLite', 'name': 'External Database Source - SQLite',
'version': '11.0.1.0.0', 'version': '11.0.1.0.1',
'category': 'Tools', 'category': 'Tools',
'author': "Daniel Reis, " 'author': "Daniel Reis, "
"LasLabs, " "LasLabs, "

View File

@@ -51,7 +51,10 @@ class BaseExternalDbsource(models.Model):
rows, cols = list(), list() rows, cols = list(), list()
for record in self: for record in self:
with record.connection_open() as connection: with record.connection_open() as connection:
cur = connection.execute(sqlquery, sqlparams) if sqlparams is None:
cur = connection.execute(sqlquery)
else:
cur = connection.execute(sqlquery, sqlparams)
if metadata: if metadata:
cols = list(cur.keys()) cols = list(cur.keys())
rows = [r for r in cur] rows = [r for r in cur]

View File

@@ -39,3 +39,12 @@ class TestBaseExternalDbsource(common.TransactionCase):
) as parent_method: ) as parent_method:
self.dbsource.execute_sqlite(*expect) self.dbsource.execute_sqlite(*expect)
parent_method.assert_called_once_with(*expect) parent_method.assert_called_once_with(*expect)
def test_execute_sqlit_without_sqlparams(self):
""" It should pass args to SQLAlchemy execute """
expect = 'sqlquery', None, 'metadata'
with mock.patch.object(
self.dbsource, '_execute_sqlalchemy'
) as parent_method:
self.dbsource.execute_sqlite(*expect)
parent_method.assert_called_once_with(*expect)