fix(community): correct inverted GOOGLE_APPLICATION_CREDENTIALS check in GoogleDriveLoader#1803
Open
Humphrey (HumphreySun98) wants to merge 1 commit into
Conversation
… in GoogleDriveLoader
`GoogleDriveLoader._load_credentials` had the ADC check inverted: it called
`google.auth.default()` when `GOOGLE_APPLICATION_CREDENTIALS` was *not* set,
and only triggered the `InstalledAppFlow` desktop-OAuth path when ADC *was*
configured. This crashed for users following the documented desktop-OAuth
quickstart (drop in `credentials.json`, no env var) with:
Your default credentials were not found. To set up Application Default
Credentials, see https://cloud.google.com/docs/authentication/external/set-up-adc
The two branches were swapped relative to the intent of each: `default()` is
the ADC helper and requires the env var, while `InstalledAppFlow` is the
desktop-OAuth helper that consumes `credentials.json`.
Adds two regression tests that pin which path each environment configuration
takes.
Fixes langchain-ai#1751
3d5d07e to
1a0afa7
Compare
Author
|
Heads-up for reviewers: the The Cloud Build log shows 4 failures, all in That is the Sheets API being blocked at the GCP project level ( Disclaimer: this PR was prepared with the assistance of an AI agent (Claude Code); all code and test changes were reviewed by the author before submission. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
GoogleDriveLoader._load_credentialshad the ADC check inverted: it calledgoogle.auth.default()whenGOOGLE_APPLICATION_CREDENTIALSwas not set,and only triggered the
InstalledAppFlowdesktop-OAuth path when ADC wasconfigured. This is backwards:
default()is the helper that requires ADC,and
InstalledAppFlowis the helper that consumes the user'scredentials.json.As reported in #1751, users who follow the documented desktop-OAuth quickstart
(drop in
credentials.json, no env var) crash with:This PR swaps the condition so each branch matches the helper it calls, and
adds two regression tests that pin the routing for both env-var states.
Relevant issues
Fixes #1751
Type
🐛 Bug Fix
Changes
libs/community/langchain_google_community/drive.py: changeelif "GOOGLE_APPLICATION_CREDENTIALS" not in os.environ:toelif "GOOGLE_APPLICATION_CREDENTIALS" in os.environ:so the ADC branch runsonly when ADC is configured.
libs/community/tests/unit_tests/test_drive.py: addtest_load_credentials_uses_installed_app_flow_when_adc_not_setandtest_load_credentials_uses_default_when_adc_set.Testing
Reverting only the one-line
drive.pychange while keeping the new tests makesboth new tests fail, confirming they actually pin the buggy path.
ruff checkandruff format --checkpass on both files.Note
The fix is intentionally minimal — a one-token swap that matches the existing
comment at the call site ("# no need to write to file" for the ADC branch,
which only makes sense if that branch corresponds to ADC). No behavior changes
in the service-account / cached-token / passed-in-
credentialspaths above.Disclaimer: this PR was prepared with the assistance of an AI agent (Claude Code). All code and test changes were reviewed by the author before submission.