Skip to content

fix(config): resolve GCP credentials from a file path, aggregate union parse errors - #4375

Open
nanjeshramesh wants to merge 1 commit into
dlt-hub:develfrom
nanjeshramesh:fix/3328-gcp-credentials-from-file-path
Open

fix(config): resolve GCP credentials from a file path, aggregate union parse errors#4375
nanjeshramesh wants to merge 1 commit into
dlt-hub:develfrom
nanjeshramesh:fix/3328-gcp-credentials-from-file-path

Conversation

@nanjeshramesh

Copy link
Copy Markdown

Description

GcpServiceAccountCredentials/GcpOAuthCredentials.parse_native_representation() called
json.loads() directly on the given string, so pointing credentials at a file path (the
common GOOGLE_APPLICATION_CREDENTIALS convention) failed to parse. Since GCS/GDrive type
credentials as Union[GcpServiceAccountCredentials, GcpOAuthCredentials], the resolver
silently fell through to try OAuth next, which also failed - and only OAuth's confusing
error surfaced to the user, even though the value was a valid service account file all along.

Two changes:

  • gcp_credentials.py: read the file's contents first when the given string is an existing
    file path, for both ServiceAccount and OAuth credentials.
  • resolve.py: when every spec in a Union fails to parse, report why each one failed
    instead of only the last one tried. This is generic to all Union-typed credentials in dlt,
    not just GCP, so it improves error messages beyond this one bug.

Related Issues

Additional Context

Added tests for both changes (file-path resolution for both credential types, and the
aggregated union error message). Full tests/common/configuration/ suite passes locally
(249 tests), ruff check/ruff format --check clean.

…n parse errors

GcpServiceAccountCredentials/GcpOAuthCredentials.parse_native_representation()
called json.loads() directly on the given string, so pointing `credentials` at
a file path (the common GOOGLE_APPLICATION_CREDENTIALS convention) failed to
parse. Since GCS/GDrive type it as Union[GcpServiceAccountCredentials,
GcpOAuthCredentials], the resolver silently fell through to try OAuth next,
which also failed, and only OAuth's confusing error surfaced to the user -
even though the value was a valid service account file all along.

- gcp_credentials.py: read the file's contents first when the given string is
  an existing file path, for both ServiceAccount and OAuth credentials.
- resolve.py: when every spec in a Union fails to parse, report why each one
  failed instead of only the last one tried. This is generic to all
  Union-typed credentials in dlt, not just GCP.

Added tests for both. Full tests/common/configuration/ suite passes (249),
ruff check/format clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dlt tries OAuth in GCP Instead of Service Account Credentials when given Service Account Credentials via credential file

1 participant