fix(gcp): surface GCP Secret Manager errors and validate DB credentials#793
Open
fix(gcp): surface GCP Secret Manager errors and validate DB credentials#793
Conversation
Previously get_key_file silently returned {} on any error, causing
str(None) → 'None' to be used as the port, leading to a cryptic
'invalid literal for int() with base 10: None' error from SQLAlchemy.
- Remove the try/except in get_key_file so GCP errors surface directly
- Validate required fields after fetching creds and raise with a clear message
- Use dict key access instead of .get() for required fields
… missing The bare 'except ModuleNotFoundError' was catching any ModuleNotFoundError raised inside the plugins module (e.g. a missing dependency), silently falling back to defaults and masking the real error. Check e.name to only fall back when 'plugins' itself is not installed.
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.
Summary
get_gcp_key_filewas silently returning{}on any Secret Manager error, causingstr(None)→'None'to be used as the DB portinvalid literal for int() with base 10: 'None'from SQLAlchemy (chained fromModuleNotFoundError: No module named 'plugins')try/exceptinget_key_fileso errors surface directlyTest plan
DB_SECRET_NAME— should connect as beforeDB_SECRET_NAME— should now get a clear GCP error instead ofint('None')ValueError: GCP DB secret '...' is missing required fields: [...]🤖 Generated with Claude Code
Greptile Summary
This PR fixes two related issues that caused a cryptic
invalid literal for int() with base 10: 'None'error during GCP database connection:get_key_fileinsecrets.pysilently caught all exceptions from GCP Secret Manager and returned{}, causing downstream code to usestr(None)as the DB port. The silenttry/exceptis removed so errors propagate directly.base.pynow validates that all required fields (username,password,clusterHost,port,dbname) are present in the GCP secret before constructing the connection URL, raising a clearValueErrorif any are missing.except ModuleNotFoundErrorblocks independencies.pyare refined to only swallow the error when thepluginsmodule itself is missing (checked viae.name.startswith("plugins")), re-raising unrelated import errors that were previously hidden. Warning logs are also added.Note: The AWS secrets module (
core/aws/secrets.py) and the AWS path inbase.py(lines 125–135) still have the same silent-error and missing-validation patterns that this PR fixes for GCP. Consider applying the same fix there as a follow-up.Confidence Score: 4/5
model-engine/model_engine_server/db/base.py— the host assignment ternary at line 90 relies on implicit operator precedence and would benefit from explicit parentheses for clarity.Important Files Changed
int('None')bug..get()to direct key access. The host assignment ternary is correct but has ambiguous formatting due to operator precedence.pluginsmodule itself, re-raising unrelated import errors. Also adds warning logs and removes unnecessaryfinally: passblocks.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[get_engine_url called] --> B{cloud_provider == gcp?} B -->|No| Z[Other providers] B -->|Yes| C{DB_SECRET_NAME set?} C -->|No| D[Use env vars: DB_USER, DB_HOST, etc.] C -->|Yes| E[get_gcp_key_file from Secret Manager] E -->|Exception| F[❌ Error propagates directly\n— was silently returning empty dict] E -->|Success| G[Validate required fields:\nusername, password, clusterHost, port, dbname] G -->|Missing fields| H[❌ ValueError with clear message\n— was producing int of None] G -->|All present| I{read_only?} I -->|Yes| J[Use clusterHostRo or fallback to clusterHost] I -->|No| K[Use clusterHost] J --> L[Build postgresql:// URL] K --> L D --> LPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix(plugins): log warning when falling b..." | Re-trigger Greptile