codeant-ai-for-open-source[bot] commented on code in PR #42803:
URL: https://github.com/apache/superset/pull/42803#discussion_r3749240766


##########
superset/databases/utils.py:
##########
@@ -72,17 +73,37 @@ def get_table_metadata(database: Any, table: Table) -> 
TableMetadataResponse:
     :return: Dict table metadata ready for API response
     """
     keys = []
-    columns = database.get_columns(table)
-    primary_key = database.get_pk_constraint(table)
+    table_missing = False
+    try:
+        columns = database.get_columns(table)
+        primary_key = database.get_pk_constraint(table)
+        foreign_keys = get_foreign_keys_metadata(database, table)
+        indexes = get_indexes_metadata(database, table)
+        table_comment = database.get_table_comment(table)
+    except NoSuchTableError:
+        # SQLAlchemy 2.0's sqlite dialect raises NoSuchTableError from
+        # reflection (get_columns/get_pk_constraint/etc.) for a table that
+        # doesn't exist - 1.4's sqlite dialect silently returned empty
+        # results instead, which this API has always relied on to answer
+        # with an empty-but-200 payload for sqlite specifically (other
+        # backends' dialects already raised on missing tables pre-2.0, so
+        # they're unaffected and still surface as the 422 below). Only
+        # sqlite gets the graceful fallback, matching that pre-existing,
+        # dialect-driven difference in behavior between backends.
+        if database.backend != "sqlite":
+            raise
+        table_missing = True

Review Comment:
   **Suggestion:** The `NoSuchTableError` handler covers the entire reflection 
sequence, not just the initial table-existence lookup. For SQLite, an error 
raised while reflecting foreign keys, indexes, comments, or another related 
object is therefore converted into an empty successful metadata response 
instead of propagating to the API's existing SQLAlchemy-error/422 handling. 
Restrict the fallback to a confirmed missing table rather than treating every 
reflection failure as table absence. [error handling]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ SQLite metadata requests can return false empty results.
   - ⚠️ Concurrent schema changes are hidden from API clients.
   - ⚠️ The table metadata endpoint reports success incorrectly.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=5ff90558c467445ca45193ec91d8818e&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=5ff90558c467445ca45193ec91d8818e&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/databases/utils.py
   **Line:** 77:95
   **Comment:**
        *Error Handling: The `NoSuchTableError` handler covers the entire 
reflection sequence, not just the initial table-existence lookup. For SQLite, 
an error raised while reflecting foreign keys, indexes, comments, or another 
related object is therefore converted into an empty successful metadata 
response instead of propagating to the API's existing SQLAlchemy-error/422 
handling. Restrict the fallback to a confirmed missing table rather than 
treating every reflection failure as table absence.
   
   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%2F42803&comment_hash=03d280d8ba0b130248db11021bb3b9e3c0843fa0e466dd48f40b6d04c58d84ab&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42803&comment_hash=03d280d8ba0b130248db11021bb3b9e3c0843fa0e466dd48f40b6d04c58d84ab&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]

Reply via email to