diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2019-04-06 10:51:03 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2019-04-06 10:51:03 +0100 |
commit | 7b31b39fedbcbb310ce1c02862c7f61d301109cf (patch) | |
tree | 2ddf53ce81dededf82037f32f27319aa178e2eab | |
parent | c64d2448e8c3948bb7f950dda51aa5d73161b20c (diff) | |
parent | 46106e1b78334114f533d4979e8d9267654f9cbd (diff) | |
download | psycopg2-7b31b39fedbcbb310ce1c02862c7f61d301109cf.tar.gz |
Merge branch 'fix-887'
-rw-r--r-- | NEWS | 7 | ||||
-rw-r--r-- | psycopg/connection_int.c | 8 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rwxr-xr-x | tests/test_async.py | 25 |
4 files changed, 34 insertions, 8 deletions
@@ -1,6 +1,13 @@ Current release --------------- +What's new in psycopg 2.8.1 +--------------------------- + +- Fixed "there's no async cursor" error polling a connection with no cursor + (:ticket:`#887`). + + What's new in psycopg 2.8 ------------------------- diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index 1f4115d..cdc6f02 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -1045,12 +1045,6 @@ static cursorObject * _conn_get_async_cursor(connectionObject *self) { PyObject *py_curs; - if (!(self->async_cursor)) { - PyErr_SetString(PyExc_SystemError, - "unexpectedly, there's no async cursor here"); - goto error; - } - if (!(py_curs = PyWeakref_GetObject(self->async_cursor))) { PyErr_SetString(PyExc_SystemError, "got null dereferencing cursor weakref"); @@ -1108,7 +1102,7 @@ conn_poll(connectionObject *self) Dprintf("conn_poll: status -> CONN_STATUS_*"); res = _conn_poll_query(self); - if (res == PSYCO_POLL_OK && self->async) { + if (res == PSYCO_POLL_OK && self->async && self->async_cursor) { cursorObject *curs; /* An async query has just finished: parse the tuple in the @@ -47,7 +47,7 @@ except ImportError: # Take a look at https://www.python.org/dev/peps/pep-0440/ # for a consistent versioning pattern. -PSYCOPG_VERSION = '2.8' +PSYCOPG_VERSION = '2.8.1.dev0' # note: if you are changing the list of supported Python version please fix diff --git a/tests/test_async.py b/tests/test_async.py index 21ef7fe..f14468e 100755 --- a/tests/test_async.py +++ b/tests/test_async.py @@ -495,6 +495,31 @@ class AsyncTests(ConnectingTestCase): self.assert_(polls >= 8, polls) + def test_poll_noop(self): + self.conn.poll() + + @skip_before_postgres(9, 0) + def test_poll_conn_for_notification(self): + with self.conn.cursor() as cur: + cur.execute("listen test") + self.wait(cur) + + with self.sync_conn.cursor() as cur: + cur.execute("notify test, 'hello'") + self.sync_conn.commit() + + for i in range(10): + self.conn.poll() + + if self.conn.notifies: + n = self.conn.notifies.pop() + self.assertEqual(n.channel, 'test') + self.assertEqual(n.payload, 'hello') + break + time.sleep(0.1) + else: + self.fail("No notification received") + def test_suite(): return unittest.TestLoader().loadTestsFromName(__name__) |