Skip to content

Commit

Permalink
fix: google sheets credential refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquimds committed Jul 2, 2024
1 parent caaf0b3 commit fdb9df1
Show file tree
Hide file tree
Showing 2 changed files with 283 additions and 260 deletions.
10 changes: 9 additions & 1 deletion hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3464,7 +3464,9 @@ def api(self):
"expiry": credentials.expiry.isoformat(),
}
)
self.save()
# Can't save here as this property is used in async contexts
# Instead, save() is called after fetch_many and update_many
# TODO: Make this not a hack!
return googleapiclient.discovery.build("sheets", "v4", credentials=credentials)

@property
Expand Down Expand Up @@ -3535,6 +3537,9 @@ async def fetch_one(self, member_id):

async def fetch_many(self, id_list: list[str]):
row_numbers = self.fetch_row_numbers_for_ids(id_list)
# Save the instance here as credentials may have been refreshed
# Can't do it in `def api` because of async complexity
await self.asave()
if not row_numbers:
return []
return self.get_rows(row_numbers)
Expand Down Expand Up @@ -3670,6 +3675,9 @@ async def update_many(self, mapped_records, **kwargs):
spreadsheetId=self.spreadsheet_id,
body={"valueInputOption": "USER_ENTERED", "data": value_ranges},
).execute()
# Save the instance here as credentials may have been refreshed
# Can't do it in `def api` because of async complexity
await self.asave()

def webhook_healthcheck(self):
message = self.check_webhook_errors()
Expand Down
Loading

0 comments on commit fdb9df1

Please sign in to comment.