From 2beb0ad1ff1b6c0686beac6afc93fadd7f65b122 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Fri, 7 Sep 2018 17:16:11 -0700 Subject: [PATCH 1/2] [BUG] Don't load credentials from disk if reauth is True If the credentials on disk are invalid, then `get_user_credentials()` may fail before it can fetch fresh credentials. Noticed first and fixed in pydata-google-auth package in https://github.com/pydata/pydata-google-auth/commit/7ce7f3f822fbaea7cc73878f52c61f8b38109f36 Note about pydata-google-auth: eventually I'd like to move pandas-gbq to use that package for auth, but since I'm not sure when I'll have that package ready, I'm patching pandas-gbq, too. --- pandas_gbq/auth.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pandas_gbq/auth.py b/pandas_gbq/auth.py index 2bc2efea..d560c61a 100644 --- a/pandas_gbq/auth.py +++ b/pandas_gbq/auth.py @@ -159,11 +159,13 @@ def get_user_account_credentials( if os.path.isfile("bigquery_credentials.dat"): os.rename("bigquery_credentials.dat", credentials_path) - credentials = load_user_account_credentials( - try_credentials, - project_id=project_id, - credentials_path=credentials_path, - ) + credentials = None + if not reauth + credentials = load_user_account_credentials( + try_credentials, + project_id=project_id, + credentials_path=credentials_path, + ) client_config = { "installed": { @@ -178,7 +180,7 @@ def get_user_account_credentials( } } - if credentials is None or reauth: + if credentials is None: app_flow = InstalledAppFlow.from_client_config( client_config, scopes=SCOPES ) From de71656548a9198c1f390a8f7ded0a354547e40c Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Fri, 7 Sep 2018 17:17:06 -0700 Subject: [PATCH 2/2] syntax error --- pandas_gbq/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas_gbq/auth.py b/pandas_gbq/auth.py index d560c61a..86ad929a 100644 --- a/pandas_gbq/auth.py +++ b/pandas_gbq/auth.py @@ -160,7 +160,7 @@ def get_user_account_credentials( os.rename("bigquery_credentials.dat", credentials_path) credentials = None - if not reauth + if not reauth: credentials = load_user_account_credentials( try_credentials, project_id=project_id,