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


##########
superset/databases/utils.py:
##########
@@ -55,7 +55,7 @@ def get_indexes_metadata(
 
 def get_col_type(col: dict[Any, Any]) -> str:
     try:
-        dtype = f"{col['type']}"
+        dtype = repr(col["type"])

Review Comment:
   **Suggestion:** Using `repr` here breaks the API output when `col["type"]` 
is already a string (which is allowed by the column typing contract): 
`repr("VARCHAR(255)")` becomes `"'VARCHAR(255)'"`, so `longType` gets extra 
quotes and the derived short `type` becomes malformed (for example 
`"'VARCHAR"`). Keep string values as-is and only use 
representation/serialization logic for non-string SQLAlchemy type objects. [api 
mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ `/databases/.../table_metadata` returns malformed column type names.
   - ⚠️ Clients consuming longType see extra-quoted type strings.
   - ⚠️ Short type parsing breaks on leading quote character.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Note the column typing contract in `superset/superset_typing.py:115-122`, 
where
   `ResultSetColumnType["type"]` is defined as `SQLType | str | None`, 
explicitly allowing
   plain strings for the `type` field.
   
   2. Create a column dict matching `ResultSetColumnType` in a test (e.g. 
alongside
   `test_get_col_type` in 
`superset/tests/unit_tests/databases/utils_test.py:48-56`) with
   `"type": "VARCHAR(255)"` (a string) and call `get_col_type(col)` from
   `superset/databases/utils.py:56-62`.
   
   3. When `get_col_type` executes line `58 dtype = repr(col["type"])` (new 
hunk),
   `repr("VARCHAR(255)")` returns the string `"'VARCHAR(255)'"`, so `dtype` now 
contains
   extra quotes compared to the original `"VARCHAR(255)"`.
   
   4. Observe how `get_table_metadata` in `superset/databases/utils.py:45-57` 
uses this
   `dtype` to build API fields: `"type": dtype.split("(")[0] if "(" in dtype 
else dtype` and
   `"longType": dtype`, so for this column the table metadata API (via
   `table_metadata_deprecated` in `superset/databases/api.py:949-958`) returns 
`"type":
   "'VARCHAR"` and `"longType": "'VARCHAR(255)'"`, producing malformed metadata 
with a
   leading quote in `type` and extra quotes in `longType` whenever a backend or 
helper
   (conforming to `ResultSetColumnType`) provides `col["type"]` as a string.
   ```
   </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=75b3f60c652a4458b948a1cf117f4cf9&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=75b3f60c652a4458b948a1cf117f4cf9&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/databases/utils.py
   **Line:** 58:58
   **Comment:**
        *Api Mismatch: Using `repr` here breaks the API output when 
`col["type"]` is already a string (which is allowed by the column typing 
contract): `repr("VARCHAR(255)")` becomes `"'VARCHAR(255)'"`, so `longType` 
gets extra quotes and the derived short `type` becomes malformed (for example 
`"'VARCHAR"`). Keep string values as-is and only use 
representation/serialization logic for non-string SQLAlchemy type objects.
   
   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%2F31587&comment_hash=d645f926d5212b7eb68438a21732f4f8ac96fb6a7936bdb545e3d22c6d411ae7&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F31587&comment_hash=d645f926d5212b7eb68438a21732f4f8ac96fb6a7936bdb545e3d22c6d411ae7&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