From 4bb86973d7cdab2f41f7aaf69596702358776e4f Mon Sep 17 00:00:00 2001 From: Sam Sciolla Date: Thu, 1 Sep 2022 11:22:49 -0400 Subject: [PATCH] Try to avoid dictionary mutation confusion --- src/officehours_api/backends/zoom.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/officehours_api/backends/zoom.py b/src/officehours_api/backends/zoom.py index 873ec91b..8afe1492 100644 --- a/src/officehours_api/backends/zoom.py +++ b/src/officehours_api/backends/zoom.py @@ -122,7 +122,7 @@ def _calculate_expires_at(cls, expires_in: int) -> float: @classmethod def _get_access_token(cls, user: User) -> str: - zoom_meta = user.profile.backend_metadata['zoom'] + zoom_meta = user.profile.backend_metadata['zoom'].copy() if time() > zoom_meta['access_token_expires']: logger.debug('Refreshing token') resp = requests.post( @@ -142,13 +142,14 @@ def _get_access_token(cls, user: User) -> str: cls._clear_backend_metadata(user) resp.raise_for_status() token = resp.json() - zoom_meta.update({ + new_zoom_data = { 'refresh_token': token['refresh_token'], 'access_token': token['access_token'], 'access_token_expires': cls._calculate_expires_at(token['expires_in']), - }) + } + user.profile.backend_metadata['zoom'].update(new_zoom_data) user.profile.save() - return zoom_meta['access_token'] + return user.profile.backend_metadata['zoom']['access_token'] @classmethod def _get_session(cls, user: User) -> requests.Session: