rusackas opened a new pull request, #42312:
URL: https://github.com/apache/superset/pull/42312
### SUMMARY
Fixes a bug where Postgres schemas whose names start with `pg` (but aren't
real system schemas), like `pgsql` or `pgstats`, silently disappeared from the
schema list in Superset (SQL Lab schema dropdown, dataset creation, etc).
The root cause is in SQLAlchemy's Postgres dialect, not Superset's own
filtering: `get_schema_names` excludes system schemas with the query `nspname
NOT LIKE 'pg_%'`. In SQL `LIKE` patterns, `_` matches any single character, so
this pattern actually matches `pg` + any one character + anything, not just the
literal `pg_` prefix used by real Postgres system schemas (`pg_catalog`,
`pg_toast`, etc). As a result, any user-created schema starting with `pg`
followed by one more character gets silently dropped.
This adds an override of `get_schema_names` in `PostgresBaseEngineSpec` that
queries `pg_namespace` directly and filters with a plain Python
`str.startswith("pg_")` check, which only excludes schemas with the real
literal prefix.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A (backend-only fix)
### TESTING INSTRUCTIONS
- Added `test_get_schema_names_excludes_only_actual_system_schemas` in
`tests/unit_tests/db_engine_specs/test_postgres.py`, which pins the bug: it
asserts that schemas like `pgsql` and `pgstats` are kept while actual system
schemas (`pg_catalog`, `pg_toast`) are excluded. This test fails without the
fix and passes with it.
- To verify manually: create a Postgres schema named e.g. `pgsql` or
`pgfoo`, then check that it now shows up in the SQL Lab schema dropdown /
dataset creation flow.
### ADDITIONAL INFORMATION
- [x] Has associated issue: Fixes #30678
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
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]