@@ -116,11 +116,13 @@ def load_credentials_from_file(filename, scopes=None, quota_project_id=None):
116
116
try :
117
117
credentials = credentials .Credentials .from_authorized_user_info (
118
118
info , scopes = scopes
119
- ). with_quota_project ( quota_project_id )
119
+ )
120
120
except ValueError as caught_exc :
121
121
msg = "Failed to load authorized user credentials from {}" .format (filename )
122
122
new_exc = exceptions .DefaultCredentialsError (msg , caught_exc )
123
123
six .raise_from (new_exc , caught_exc )
124
+ if quota_project_id :
125
+ credentials = credentials .with_quota_project (quota_project_id )
124
126
if not credentials .quota_project_id :
125
127
_warn_about_problematic_credentials (credentials )
126
128
return credentials , None
@@ -131,11 +133,13 @@ def load_credentials_from_file(filename, scopes=None, quota_project_id=None):
131
133
try :
132
134
credentials = service_account .Credentials .from_service_account_info (
133
135
info , scopes = scopes
134
- ). with_quota_project ( quota_project_id )
136
+ )
135
137
except ValueError as caught_exc :
136
138
msg = "Failed to load service account credentials from {}" .format (filename )
137
139
new_exc = exceptions .DefaultCredentialsError (msg , caught_exc )
138
140
six .raise_from (new_exc , caught_exc )
141
+ if quota_project_id :
142
+ credentials = credentials .with_quota_project (quota_project_id )
139
143
return credentials , info .get ("project_id" )
140
144
141
145
else :
@@ -317,9 +321,10 @@ def default(scopes=None, request=None, quota_project_id=None):
317
321
for checker in checkers :
318
322
credentials , project_id = checker ()
319
323
if credentials is not None :
320
- credentials = with_scopes_if_required (
321
- credentials , scopes
322
- ).with_quota_project (quota_project_id )
324
+ credentials = with_scopes_if_required (credentials , scopes )
325
+ if quota_project_id :
326
+ credentials = credentials .with_quota_project (quota_project_id )
327
+
323
328
effective_project_id = explicit_project_id or project_id
324
329
if not effective_project_id :
325
330
_LOGGER .warning (
0 commit comments