codeant-ai-for-open-source[bot] commented on code in PR #42312:
URL: https://github.com/apache/superset/pull/42312#discussion_r3651455994
##########
superset/db_engine_specs/postgres.py:
##########
@@ -793,6 +793,29 @@ def get_catalog_names(
)
}
+ @classmethod
+ def get_schema_names(cls, inspector: Inspector) -> set[str]:
+ """
+ Return all schema names, excluding the ``pg_``-prefixed Postgres
+ system schemas (e.g. ``pg_catalog``, ``pg_toast``).
+
+ SQLAlchemy's Postgres dialect filters out system schemas with the
+ query ``nspname NOT LIKE 'pg_%'``. Since ``_`` is a single-character
+ wildcard in SQL ``LIKE`` patterns, this unintentionally excludes any
+ user-defined schema that merely starts with ``pg`` followed by any
+ other character (e.g. ``pgsql``, ``pgstats``), not only the
+ ``pg_``-prefixed system schemas. Matching on the literal ``pg_``
+ prefix instead keeps those user-defined schemas.
+ """
+ with inspector.engine.connect() as conn:
+ return {
+ name
+ for (name,) in conn.execute(
+ text("SELECT nspname FROM pg_namespace ORDER BY nspname")
+ )
+ if not name.startswith("pg_")
+ }
Review Comment:
**Suggestion:** The `startswith("pg_")` filter still removes every schema
with a literal `pg_` prefix, including valid user-created schemas such as
`pg_custom`; PostgreSQL does not reserve that prefix for system schemas. This
only fixes the SQL wildcard overmatching while preserving the original
false-positive behavior for user schemas. Filter the actual system schemas
explicitly or otherwise distinguish system namespaces from user-created ones.
[logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ User-created `pg_` schemas disappear from metadata.
- ⚠️ SQL Lab schema selection omits affected schemas.
- ⚠️ Dataset creation cannot select affected schemas.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Connect Superset to a PostgreSQL database and create a user schema named
`pg_custom`,
which is permitted by PostgreSQL and has the literal `pg_` prefix.
2. Trigger Superset's PostgreSQL schema metadata flow, which invokes
`PostgresBaseEngineSpec.get_schema_names()` at
`superset/db_engine_specs/postgres.py:797`.
3. The method queries all namespaces at
`superset/db_engine_specs/postgres.py:810-815`,
then evaluates each result using `name.startswith("pg_")` at line 817.
4. Observe that `pg_custom` is removed from the returned set along with
`pg_catalog` and
`pg_toast`, so it remains unavailable in schema-list consumers such as SQL
Lab and dataset
creation. Distinguishing actual system namespaces from user namespaces is
required to
retain valid user-created `pg_` schemas.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=d190e05ae28b4279b05322791de45b3c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=d190e05ae28b4279b05322791de45b3c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/db_engine_specs/postgres.py
**Line:** 817:817
**Comment:**
*Logic Error: The `startswith("pg_")` filter still removes every schema
with a literal `pg_` prefix, including valid user-created schemas such as
`pg_custom`; PostgreSQL does not reserve that prefix for system schemas. This
only fixes the SQL wildcard overmatching while preserving the original
false-positive behavior for user schemas. Filter the actual system schemas
explicitly or otherwise distinguish system namespaces from user-created ones.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42312&comment_hash=72879b73d7966d0996b44895051135f24cf3c294bde37a16f9cad7e8814ea09a&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42312&comment_hash=72879b73d7966d0996b44895051135f24cf3c294bde37a16f9cad7e8814ea09a&reaction=dislike'>👎</a>
--
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]