Skip to content

Commit

Permalink
Fix for COMPY-39:
Browse files Browse the repository at this point in the history
If pool_name wasn't specified, the initialization of ConnectionPool() failed.
We now check if pool_name wasn't provided and return an exception.
  • Loading branch information
9EOR9 committed Jan 25, 2020
1 parent ad85042 commit b29f042
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/mariadb_pooling.c
Expand Up @@ -116,7 +116,7 @@ MrdbPool_initialize(MrdbPool *self, PyObject *args, PyObject *kwargs)
}

/* check if pool already exists */
if ((pn= PyDict_GetItemString(kwargs, "pool_name")))
if (kwargs && (pn= PyDict_GetItemString(kwargs, "pool_name")))
{
if (PyDict_Contains(cnx_pool, pn))
{
Expand All @@ -125,6 +125,11 @@ MrdbPool_initialize(MrdbPool *self, PyObject *args, PyObject *kwargs)
return -1;
}
}
else {
mariadb_throw_exception(NULL, Mariadb_ProgrammingError, 0,
"No pool name specified");
return -1;
}

while(PyDict_Next(kwargs, &pos, &key, &value))
{
Expand Down
6 changes: 6 additions & 0 deletions test/integration/test_pooling.py
Expand Up @@ -27,6 +27,12 @@ def test_connection_pools(self):
del pool
self.assertEqual(mariadb._CONNECTION_POOLS, {})

def test_conpy39(self):
try:
pool= mariadb.ConnectionPool()
except mariadb.ProgrammingError:
pass

def test_connection_pool_conf(self):
pool= mariadb.ConnectionPool(pool_name="test")
default_conf= conf()
Expand Down

0 comments on commit b29f042

Please sign in to comment.