summaryrefslogtreecommitdiff
path: root/psycopg/psycopgmodule.c
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-04-05 18:31:09 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-04-05 18:31:09 +0100
commitc75ddea89530339a697b68b5d06137d07c64854b (patch)
treeaf5915c1eb54ea662abd62ff7eca037374b9b85a /psycopg/psycopgmodule.c
parentc486136df7323925f65938f6421e5a71870a4ed2 (diff)
downloadpsycopg2-c75ddea89530339a697b68b5d06137d07c64854b.tar.gz
Pass the async parameter to the connection only if nonzero.
This avoids breaking connection subclasses redefining '__init__' (at least when used sync, which is good for most of the people).
Diffstat (limited to 'psycopg/psycopgmodule.c')
-rw-r--r--psycopg/psycopgmodule.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c
index 8ececea..528c592 100644
--- a/psycopg/psycopgmodule.c
+++ b/psycopg/psycopgmodule.c
@@ -197,7 +197,18 @@ psyco_connect(PyObject *self, PyObject *args, PyObject *keywds)
/* allocate connection, fill with errors and return it */
if (factory == NULL) factory = (PyObject *)&connectionType;
- conn = PyObject_CallFunction(factory, "si", dsn, async);
+ /* Here we are breaking the connection.__init__ interface defined
+ * by psycopg2. So, if not requiring an async conn, avoid passing
+ * the async parameter. */
+ /* TODO: would it be possible to avoid an additional parameter
+ * to the conn constructor? A subclass? (but it would require mixins
+ * to further subclass) Another dsn parameter (but is not really
+ * a connection parameter that can be configured) */
+ if (!async) {
+ conn = PyObject_CallFunction(factory, "s", dsn);
+ } else {
+ conn = PyObject_CallFunction(factory, "si", dsn, async);
+ }
}
goto cleanup;