Fixed explicit connection.cursor(cursor_factory=None)

Fixes issue #210.
This commit is contained in:
Daniele Varrazzo 2014-04-30 17:56:09 +01:00
parent e1eb7a71b0
commit a1344f30f3
3 changed files with 14 additions and 1 deletions

2
NEWS
View File

@ -26,6 +26,8 @@ What's new in psycopg 2.4.7
happens for TCP connections instead (:ticket:`#196`).
- Fixed overflow opening a lobject with an oid not fitting in a signed int
(:ticket:`#203`).
- Fixed handling of explicit default ``cursor_factory=None`` in
`connection.cursor()` (:ticket:`#210`).
- Mark the connection closed if found broken on `poll()`.
- Fixed possible segfault in named cursors creation.
- Fixed debug build on Windows, thanks to James Emerton.

View File

@ -54,7 +54,7 @@ psyco_conn_cursor(connectionObject *self, PyObject *args, PyObject *kwargs)
{
PyObject *obj;
PyObject *name = Py_None;
PyObject *factory = (PyObject *)&cursorType;
PyObject *factory = Py_None;
PyObject *withhold = Py_False;
static char *kwlist[] = {"name", "cursor_factory", "withhold", NULL};
@ -72,6 +72,10 @@ psyco_conn_cursor(connectionObject *self, PyObject *args, PyObject *kwargs)
EXC_IF_CONN_CLOSED(self);
if (factory == Py_None) {
factory = (PyObject *)&cursorType;
}
if (self->status != CONN_STATUS_READY &&
self->status != CONN_STATUS_BEGIN &&
self->status != CONN_STATUS_PREPARED) {

View File

@ -218,6 +218,13 @@ class ConnectionTests(unittest.TestCase):
self.assert_(not notices, "%d notices raised" % len(notices))
def test_cursor_factory_none(self):
# issue #210
conn = psycopg2.connect(dsn)
cur = conn.cursor(cursor_factory=None)
self.assertEqual(type(cur), psycopg2.extensions.cursor)
conn.close()
def test_failed_init_status(self):
class SubConnection(psycopg2.extensions.connection):
def __init__(self, dsn):