Skip to content

fix(community): correct inverted GOOGLE_APPLICATION_CREDENTIALS check in GoogleDriveLoader#1803

Open
Humphrey (HumphreySun98) wants to merge 1 commit into
langchain-ai:mainfrom
HumphreySun98:fix/drive-load-credentials-inverted-adc-check
Open

fix(community): correct inverted GOOGLE_APPLICATION_CREDENTIALS check in GoogleDriveLoader#1803
Humphrey (HumphreySun98) wants to merge 1 commit into
langchain-ai:mainfrom
HumphreySun98:fix/drive-load-credentials-inverted-adc-check

Conversation

@HumphreySun98

@HumphreySun98 Humphrey (HumphreySun98) commented May 25, 2026

Copy link
Copy Markdown

Description

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 is backwards: default() is the helper that requires ADC,
and InstalledAppFlow is the helper that consumes the user's credentials.json.

As reported in #1751, users who follow the documented desktop-OAuth quickstart
(drop in credentials.json, no env var) crash with:

Your default credentials were not found. To set up Application Default
Credentials, see https://cloud.google.com/docs/authentication/external/set-up-adc

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: change
    elif "GOOGLE_APPLICATION_CREDENTIALS" not in os.environ: to
    elif "GOOGLE_APPLICATION_CREDENTIALS" in os.environ: so the ADC branch runs
    only when ADC is configured.
  • libs/community/tests/unit_tests/test_drive.py: add
    test_load_credentials_uses_installed_app_flow_when_adc_not_set and
    test_load_credentials_uses_default_when_adc_set.

Testing

$ python -m pytest libs/community/tests/unit_tests/test_drive.py -v
...
test_load_credentials_uses_installed_app_flow_when_adc_not_set PASSED
test_load_credentials_uses_default_when_adc_set                PASSED
======================= 10 passed in 5.11s =======================

Reverting only the one-line drive.py change while keeping the new tests makes
both new tests fail, confirming they actually pin the buggy path.

ruff check and ruff format --check pass 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-credentials paths 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.

… 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
@HumphreySun98 Humphrey (HumphreySun98) force-pushed the fix/drive-load-credentials-inverted-adc-check branch from 3d5d07e to 1a0afa7 Compare May 25, 2026 18:49
@HumphreySun98

Copy link
Copy Markdown
Author

Heads-up for reviewers: the langchain-google-community-us (llm-integration-tests) red mark is unrelated to this PR.

The Cloud Build log shows 4 failures, all in tests/integration_tests/test_sheets_integration.py, all the same error:

HttpError 403: API_KEY_SERVICE_BLOCKED
"Requests to this API sheets.googleapis.com method ... are blocked"
consumer: projects/546814358370

That is the Sheets API being blocked at the GCP project level (llm-integration-tests), not anything this PR touches — this PR only changes a single token in drive.py and adds drive-only unit tests. The same check shows FAILURE on a prior external community PR (#1721), which was still merged. Unit tests, lint, and compile-integration are all green here.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant