diff --git a/NEWS b/NEWS index 94f6bdbf..7528d78b 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ What's new in psycopg 2.7.4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - Fixed Solaris 10 support (:ticket:`#532`). +- `cursor.mogrify()` can be called on closed cursors (:ticket:`#579`). - Fixed `~psycopg2.extras.MinTimeLoggingCursor` on Python 3 (:ticket:`#609`). - Fixed parsing of array of points as floats (:ticket:`#613`). - Fixed `~psycopg2.__libpq_version__` building with libpq >= 10.1 diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index a70e9d34..b7fd1870 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -592,8 +592,6 @@ psyco_curs_mogrify(cursorObject *self, PyObject *args, PyObject *kwargs) return NULL; } - EXC_IF_CURS_CLOSED(self); - return _psyco_curs_mogrify(self, operation, vars); } diff --git a/tests/test_cursor.py b/tests/test_cursor.py index 580cf9b1..7a98e26d 100755 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -121,6 +121,12 @@ class CursorTests(ConnectingTestCase): nref2 = sys.getrefcount(foo) self.assertEqual(nref1, nref2) + def test_modify_closed(self): + cur = self.conn.cursor() + cur.close() + sql = cur.mogrify("select %s", (10,)) + self.assertEqual(sql, b"select 10") + def test_bad_placeholder(self): cur = self.conn.cursor() self.assertRaises(psycopg2.ProgrammingError,