diff options
| author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-04-05 18:31:09 +0100 |
|---|---|---|
| committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-04-05 18:31:09 +0100 |
| commit | c75ddea89530339a697b68b5d06137d07c64854b (patch) | |
| tree | af5915c1eb54ea662abd62ff7eca037374b9b85a /psycopg/psycopgmodule.c | |
| parent | c486136df7323925f65938f6421e5a71870a4ed2 (diff) | |
| download | psycopg2-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.c | 13 |
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; |
