eschutho opened a new pull request, #45867: URL: https://github.com/apache/superset/pull/45867
<!--- Please write the PR title following the conventions at https://www.conventionalcommits.org/en/v1.0.0/ --> ### SUMMARY Handle `sqlalchemy.exc.ProgrammingError` (and other non-`OperationalError` `DBAPIError`s) raised while connecting to a user database, instead of letting them escape as unhandled 500s with ERROR logs. ### PROBLEM Some Postgres-wire-compatible engines don't implement every GUC that SQLAlchemy's `postgresql` dialect queries on first connect (e.g. `SHOW standard_conforming_strings`). The resulting `ProgrammingError` is a sibling of `OperationalError` under `DBAPIError`, so it escapes two places: - `GET /api/v1/database/<pk>/schemas/` (and `/catalogs/`) only catch `OperationalError`. - `POST|GET /api/v1/chart/data`: the connection is first opened while computing the cache key (`query_cache_key` -> `get_extra_cache_keys` -> `get_default_schema` -> `get_inspector`), which runs outside the code that wraps query-execution failures as `ChartDataQueryFailedError`, so a raw `DBAPIError` reaches `_get_data_response` unhandled. ### FIX - `schemas` / `catalogs`: catch `DBAPIError` (these endpoints run no user SQL, so any DBAPI error is a connect/introspection failure). Response is unchanged (500, "There was an error connecting to the database"); a WARNING with traceback is now logged. - `_get_data_response`: catch `DBAPIError`, log at WARNING, return 422 with a generic message passed through `sanitize_error_message` (raw driver error / SQL is not returned). ### Tradeoffs - Any `DBAPIError` raised while acquiring the chart payload (including transient connection drops) now returns 422 instead of 500. - Not covered: `ChartDataRestApi._run_async` has a similar gap for `async_mode` requests; left for a follow-up since the fix there differs. ### TESTING INSTRUCTIONS `pytest tests/unit_tests/databases/api_test.py tests/unit_tests/charts/test_chart_data_api.py` (new tests fail on master, pass here). ### ADDITIONAL INFORMATION - [ ] Has associated issue: - [ ] Required feature flags: - [ ] Changes UI - [ ] Includes DB Migration - [ ] Introduces new feature or API - [ ] Removes existing feature or API 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
