Indeed, it appears that the connection.cursor()
implementation doesn't handle setting the cursor_factory
argument to None
very well.
The code doesn't check for factory
being set to Py_None
and calls it regardless. If the keyword argument isn't given connection.cursor_factory
is used instead, which is, according to the source, set to extensions.cursor
(e.g. psycopg2._psycopg.cursor
) by default.
You can replicate this by testing for None
and using connection.cursor_factory
instead in that case:
def fetchcursor(self, query, params, in_cursor_factory=None):
if in_cursor_factory is None:
in_cursor_factory = self.conn.cursor_factory
cur = self.conn.cursor(cursor_factory=in_cursor_factory)
cur.execute(query, params)
return cur
This presumes you are using psycopg
version 2.5 or newer; connection.cursor_factory
was added in that version.
For previous versions just use psycopg2._psycopg.cursor
instead of self.conn.cursor_factory
.