@@ -116,11 +116,13 @@ def load_credentials_from_file(filename, scopes=None, quota_project_id=None):
116116 try :
117117 credentials = credentials .Credentials .from_authorized_user_info (
118118 info , scopes = scopes
119- ). with_quota_project ( quota_project_id )
119+ )
120120 except ValueError as caught_exc :
121121 msg = "Failed to load authorized user credentials from {}" .format (filename )
122122 new_exc = exceptions .DefaultCredentialsError (msg , caught_exc )
123123 six .raise_from (new_exc , caught_exc )
124+ if quota_project_id :
125+ credentials = credentials .with_quota_project (quota_project_id )
124126 if not credentials .quota_project_id :
125127 _warn_about_problematic_credentials (credentials )
126128 return credentials , None
@@ -131,11 +133,13 @@ def load_credentials_from_file(filename, scopes=None, quota_project_id=None):
131133 try :
132134 credentials = service_account .Credentials .from_service_account_info (
133135 info , scopes = scopes
134- ). with_quota_project ( quota_project_id )
136+ )
135137 except ValueError as caught_exc :
136138 msg = "Failed to load service account credentials from {}" .format (filename )
137139 new_exc = exceptions .DefaultCredentialsError (msg , caught_exc )
138140 six .raise_from (new_exc , caught_exc )
141+ if quota_project_id :
142+ credentials = credentials .with_quota_project (quota_project_id )
139143 return credentials , info .get ("project_id" )
140144
141145 else :
@@ -317,9 +321,10 @@ def default(scopes=None, request=None, quota_project_id=None):
317321 for checker in checkers :
318322 credentials , project_id = checker ()
319323 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+
323328 effective_project_id = explicit_project_id or project_id
324329 if not effective_project_id :
325330 _LOGGER .warning (
0 commit comments