Repository navigation
Normalize empty project id in credential config file branch - #73886
Conversation
google-auth's load_credentials_from_file returns `str | None` for the project id, but _get_credentials_using_credential_config_file is annotated `-> tuple[Credentials, str]` and could hand `None` back to callers. The ADC branch (apache#61654) and the IdP branch (apache#72799) already normalize a missing project id to an empty string so the consumer decides how to handle it; this makes the third and last branch consistent with them, as suggested in the review of apache#72799.
|
Hi @wiasliaw, Thank you for your PR! In the google provider side, we want to also see the system tests results after a change. Thank you in advance! |
|
Hi, @molcay
|
shahar1
left a comment
There was a problem hiding this comment.
Brings the plain credential_config_file branch in line with the ADC and IdP branches: a None project id from google.auth.load_credentials_from_file is now normalised to "", so the return value matches the declared tuple[Credentials, str]. I checked the callers (GoogleBaseHook, the Secret Manager backend, the GCS/Cloud Logging task handlers): all of them test the project id for truthiness, so behaviour is unchanged, and the new test covers the string-config path that previously returned None.
This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.More on how Apache Airflow handles maintainer review:
Contributing guide.
Why
google.auth.load_credentials_from_filereturnsstr | Nonefor the project id, but_CredentialProvider._get_credentials_using_credential_config_fileis annotated-> tuple[Credentials, str]and passed theNonethrough unchanged.credential_config_filebranch was the last one handing backNonedespite itsstrannotation.GoogleBaseHookoverrides with the connection'sprojectextra andfallback_to_default_project_idraises when nothing provides a project id), so""andNonetake identical paths. The fix makes the actual return type match the declared one and keeps the three branches consistent.How
""before the shared return in_get_credentials_using_credential_config_file, same pattern as the ADC and IdP branches.test_get_credentials_using_credential_config_file_no_project_id, which mocksgoogle.auth.load_credentials_from_filereturning aNoneproject id and asserts the provider returns"". The credentials mock usesmock.create_autospec(Credentials, instance=True)per the review suggestion on Fix Google IdP credentials failing when project id cannot be resolved #72799.related: #72799, #61654
Verification
uv run --project providers/google pytest providers/google/tests/unit/google/cloud/utils/test_credentials_provider.py— 45 passed.Noneinstead of"").ruff formatandruff checkpass on both changed files.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Fable 5) following the guidelines