From d25d27846a3f3ed7eb673a93cc9e7691b99fe36b Mon Sep 17 00:00:00 2001 From: Irina Truong Date: Mon, 4 Mar 2019 16:52:39 -0800 Subject: Fix for https://github.com/dbcli/pgcli/issues/1014. --- pgcli/pgexecute.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pgcli/pgexecute.py b/pgcli/pgexecute.py index 4deaf279..8c3bfa82 100644 --- a/pgcli/pgexecute.py +++ b/pgcli/pgexecute.py @@ -354,7 +354,13 @@ class PGExecute(object): if pgspecial: # First try to run each query as special _logger.debug('Trying a pgspecial command. sql: %r', sql) - cur = self.conn.cursor() + try: + cur = self.conn.cursor() + except psycopg2.InterfaceError: + # edge case when connection is already closed, but we + # don't need cursor for special_cmd.arg_type == NO_QUERY. + # See https://github.com/dbcli/pgcli/issues/1014. + cur = None try: for result in pgspecial.execute(cur, sql): # e.g. execute_from_file already appends these -- cgit v1.2.3