diff options
author | Irina Truong <i.chernyavska@gmail.com> | 2018-07-04 12:36:42 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-04 12:36:42 -0700 |
commit | d5b0b6527bb7d962de7a7494b8335008e15cf23d (patch) | |
tree | ed075fce158820df8ac2fa6f520e368c8bc00b3d | |
parent | 2e6e0e4acd66d4a29b64c9f3a5a08b5a9527ae80 (diff) | |
parent | e5ced8d27ec0e190c0b2593ba7bd178e127bc944 (diff) |
Merge pull request #901 from benchling/fix-reconnect
Avoid reconnect prompt after error if connection is still valid
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | changelog.rst | 3 | ||||
-rw-r--r-- | pgcli/pgexecute.py | 13 |
3 files changed, 7 insertions, 10 deletions
@@ -81,6 +81,7 @@ Contributors: * Rishi Ramraj * Matthieu Guilbert * Alexandr Korsak + * Saif Hakim Creator: diff --git a/changelog.rst b/changelog.rst index 266b6a69..5dd8512a 100644 --- a/changelog.rst +++ b/changelog.rst @@ -20,7 +20,7 @@ Internal changes: Bug Fixes: ---------- * Disable pager when using \watch (#837). (Thanks: `Jason Ribeiro`_) -* Don't offer to reconnect when we can't change a param in realtime (#807). (Thanks: `Amjith Ramanujam`_) +* Don't offer to reconnect when we can't change a param in realtime (#807). (Thanks: `Amjith Ramanujam`_ and `Saif Hakim`_) * Make keyring optional. (Thanks: `Dick Marinus`_) * Fix ipython magic connection (#891). (Thanks: `Irina Truong`_) * Fix not enough values to unpack. (Thanks: `Matthieu Guilbert`_) @@ -837,3 +837,4 @@ Improvements: .. _`Rishi Ramraj`: https://github.com/RishiRamraj .. _`Matthieu Guilbert`: https://github.com/gma2th .. _`Alexandr Korsak`: https://github.com/oivoodoo +.. _`Saif Hakim`: https://github.com/saifelse diff --git a/pgcli/pgexecute.py b/pgcli/pgexecute.py index 29dfa1ba..58986aca 100644 --- a/pgcli/pgexecute.py +++ b/pgcli/pgexecute.py @@ -354,21 +354,16 @@ 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)""" |