Fix CloudSecretManagerBackend regression with explicit project_id (issue #61217) #61654
+12
−11
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.
Summary
Fixes #61217: CloudSecretManagerBackend with explicit
project_idfails when Application Default Credentials (ADC) have no default project.Root Cause
_get_credentials_using_adc()raises anAirflowExceptionwhengoogle.auth.default()returnsNoneproject_id. This occurs beforeCloudSecretManagerBackend.__init__can apply the explicitproject_idparameter, causing the backend to fail even when a valid project ID is provided.Changes
credentials_provider.py–_get_credentials_using_adc()now returns an empty string ("") instead of raising when ADC yieldsNoneproject_id.secret_manager.py– Added validation in__init__that raisesAirflowExceptionif neither ADC nor the explicitproject_idparameter provides a project ID.blackandisortto both modified files.Backward Compatibility
CloudSecretManagerBackend.__init__with a clearer message.project_idnow work correctly – the explicit parameter is honored.get_credentials_and_project_id()still returnstuple[Credentials, str](empty string is a validstr).Testing
CloudSecretManagerBackendandcredentials_providerpass because they mockgoogle.auth.defaultto return a valid project ID.test_credentials_provider.py:test_get_credentials_and_project_id_with_default_auth_no_project_idverifies thatget_credentials_and_project_id()returns an empty string when ADC yieldsNoneproject_id.CloudSecretManagerBackend(project_id="my-project")now works when ADC lacks a default project.Impact on Other Callers
Other components that call
get_credentials_and_project_id()without an explicitkey_secret_project_idwill receive an empty string instead of anAirflowException. If those components do not validate the project ID, they may propagate the empty string to downstream Google APIs, which will produce a different error (e.g., “Invalid project”). This is acceptable because:project_idbeing ignored) is fixed.key_secret_project_id(or similar).Checklist
Related Issues