diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index d033a3df..5dd08cc9 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -1624,8 +1624,6 @@ psyco_curs_start_replication_expert(cursorObject *self, PyObject *args, PyObject Py_INCREF(res); } - self->repl_started = 1; - return res; } @@ -1676,6 +1674,8 @@ psyco_curs_consume_replication_stream(cursorObject *self, PyObject *args, PyObje return NULL; } + self->repl_started = 1; + if (pq_copy_both(self, consumer, decode, keepalive_interval) >= 0) { res = Py_None; Py_INCREF(res); diff --git a/tests/test_connection.py b/tests/test_connection.py index 91ea51f5..18f1ff3e 100755 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -1197,6 +1197,18 @@ class ReplicationTest(ConnectingTestCase): cur.execute("IDENTIFY_SYSTEM") cur.fetchall() + @skip_before_postgres(9, 0) + def test_stop_replication_raises(self): + import psycopg2.extras + conn = self.repl_connect(connection_factory=psycopg2.extras.PhysicalReplicationConnection) + if conn is None: return + cur = conn.cursor() + self.assertRaises(psycopg2.ProgrammingError, cur.stop_replication) + + cur.start_replication() + self.assertRaises(psycopg2.ProgrammingError, cur.stop_replication) + + def test_suite(): return unittest.TestLoader().loadTestsFromName(__name__)