From e65a1e6afa16e83a2e4f065a9bca2ce144833748 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 21 Dec 2022 13:27:53 +0000 Subject: [PATCH] companion: Have `Session.close()` actually open a new one by default Both current callers to this are in code paths where it is expected that Session.requests_session will be valid later. Rather than assign a new session at the call sites just make this by default open a new session. --- companion.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/companion.py b/companion.py index 1c68e38b..9cf69b42 100644 --- a/companion.py +++ b/companion.py @@ -733,7 +733,7 @@ class Session(object): self.auth = None raise # Bad thing happened - def close(self) -> None: + def close(self, reopen: bool = True) -> None: """Close Frontier authorization session.""" self.state = Session.STATE_INIT if self.requests_session: @@ -742,8 +742,11 @@ class Session(object): except Exception as e: logger.debug('Frontier Auth: closing', exc_info=e) + self.requests_session = None - self.requests_session = None + # 2022-12-21: Current callers all need a *new* session. + if reopen: + self.requests_session = requests.Session() def invalidate(self) -> None: """Invalidate Frontier authorization credentials."""