Skip to content

Commit

Permalink
Try to avoid dictionary mutation confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
ssciolla committed Sep 6, 2022
1 parent f8f5aad commit 4bb8697
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/officehours_api/backends/zoom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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:
Expand Down

0 comments on commit 4bb8697

Please sign in to comment.