diff options
author | Saif Hakim <saif@benchling.com> | 2018-07-03 23:06:34 -0700 |
---|---|---|
committer | Saif Hakim <saif@benchling.com> | 2018-07-03 23:56:26 -0700 |
commit | 5cdb15199985f9e79f434aa1af302d4ab0523fdc (patch) | |
tree | 3cf1d450477e90795485c7299a6f65224f1ce6dd /pgcli/pgexecute.py | |
parent | 2e6e0e4acd66d4a29b64c9f3a5a08b5a9527ae80 (diff) |
Avoid reconnect prompt after error if connection is still valid
Instead of whitelisting all errors that do not require reconnecting, we simply
only reconnect if we detect a disconnect has occurred.
psql notably behaves in a similar way: https://git.io/fbxuc#L1461
Fixes #807
Diffstat (limited to 'pgcli/pgexecute.py')
-rw-r--r-- | pgcli/pgexecute.py | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/pgcli/pgexecute.py b/pgcli/pgexecute.py index 29dfa1ba..21554580 100644 --- a/pgcli/pgexecute.py +++ b/pgcli/pgexecute.py @@ -353,22 +353,17 @@ class PGExecute(object): def _must_raise(self, e): """Return true if e is an error that should not be caught in ``run``. - - ``OperationalError``s are raised for errors that are not under the - control of the programmer. Usually that means unexpected disconnects, - which we shouldn't catch; we handle uncaught errors by prompting the - user to reconnect. We *do* want to catch OperationalErrors caused by a - lock being unavailable, as reconnecting won't solve that problem. + + An uncaught error will prompt the user to reconnect; as long as we + detect that the connection is stil open, we catch the error, as + reconnecting won't solve that problem. :param e: DatabaseError. An exception raised while executing a query. :return: Bool. True if ``run`` must raise this exception. """ - return (isinstance(e, psycopg2.OperationalError) and - (not e.pgcode or - psycopg2.errorcodes.lookup(e.pgcode) not in - ('LOCK_NOT_AVAILABLE', 'CANT_CHANGE_RUNTIME_PARAM'))) + return self.conn.closed != 0 def execute_normal_sql(self, split_sql): """Returns tuple (title, rows, headers, status)""" |