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).
{
'name': 'External Database Source - SQLite',
'version': '11.0.1.0.0',
'version': '11.0.1.0.1',
'category': 'Tools',
'author': "Daniel Reis, "
"LasLabs, "

View File

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

View File

@@ -39,3 +39,12 @@ class TestBaseExternalDbsource(common.TransactionCase):
) as parent_method:
self.dbsource.execute_sqlite(*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)