codeant-ai-for-open-source[bot] commented on code in PR #42821:
URL: https://github.com/apache/superset/pull/42821#discussion_r3737110390
##########
superset/db_engine_specs/mysql.py:
##########
@@ -403,22 +440,22 @@ def get_schema_from_engine_params(
@classmethod
def get_datatype(cls, type_code: Any) -> Optional[str]:
- if not cls.type_code_map:
- # only import and store if needed at least once
- # pylint: disable=import-outside-toplevel
- try:
- import MySQLdb
-
- mysql_module = MySQLdb
- except ImportError:
- mysql_module = __import__("pymysql")
-
- ft = mysql_module.constants.FIELD_TYPE
- cls.type_code_map = {
- getattr(ft, k): k for k in dir(ft) if not k.startswith("_")
- }
datatype = type_code
if isinstance(type_code, int):
+ if not cls.type_code_map:
+ # only import and store if needed at least once
+ # pylint: disable=import-outside-toplevel
+ try:
+ import MySQLdb
+
+ mysql_module = MySQLdb
+ except ImportError:
+ mysql_module = __import__("pymysql")
+
+ ft = mysql_module.constants.FIELD_TYPE
Review Comment:
**Suggestion:** The integer type-code path only attempts `MySQLdb` and then
unconditionally imports `pymysql`, even though this engine explicitly supports
`mysql+mysqlconnector` connections. In an environment with only
`mysql-connector-python` installed, fetching any result with integer
wire-protocol type codes raises `ModuleNotFoundError` before the query results
can be processed. Resolve the field-type constants from the active SQLAlchemy
driver or add a `mysql.connector` fallback using its actual field-type API.
[api mismatch]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ SQL Lab result fetching fails for mysqlconnector-only deployments.
- ❌ Virtual dataset metadata queries cannot resolve column types.
- ⚠️ Supported connector configuration requires an unrelated PyMySQL
dependency.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=9a039935a2394f958120584004ed1793&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=9a039935a2394f958120584004ed1793&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/mysql.py
**Line:** 448:455
**Comment:**
*Api Mismatch: The integer type-code path only attempts `MySQLdb` and
then unconditionally imports `pymysql`, even though this engine explicitly
supports `mysql+mysqlconnector` connections. In an environment with only
`mysql-connector-python` installed, fetching any result with integer
wire-protocol type codes raises `ModuleNotFoundError` before the query results
can be processed. Resolve the field-type constants from the active SQLAlchemy
driver or add a `mysql.connector` fallback using its actual field-type API.
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%2F42821&comment_hash=c11b3a81de82d2cfd40336351a3f044a72474938fa7d2ab2bb1ce44a870eaff5&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42821&comment_hash=c11b3a81de82d2cfd40336351a3f044a72474938fa7d2ab2bb1ce44a870eaff5&reaction=dislike'>👎</a>
##########
superset/db_engine_specs/mysql.py:
##########
@@ -245,6 +245,43 @@ class MySQLEngineSpec(BasicParametersMixin,
BaseEngineSpec):
types.VARCHAR(),
GenericDataType.STRING,
),
+ # wire-protocol FIELD_TYPE names emitted by `get_datatype`, seen on
+ # SQL Lab and virtual dataset columns instead of DDL type names
+ (
+ re.compile(r"^newdecimal", re.IGNORECASE),
+ DECIMAL(),
+ GenericDataType.NUMERIC,
+ ),
Review Comment:
**Suggestion:** Adding the `NEWDECIMAL` mapping activates the decimal
mutator for MySQL result sets, but the mutator bookkeeping is keyed by column
name rather than column position. Queries with duplicate labels, such as
selecting two expressions both aliased as `amount`, can therefore omit
conversion of the first decimal column or apply conversion to the wrong
occurrence depending on the order and types of the duplicate columns. Track
mutators by description index so every matching result column is handled
independently. [incorrect variable usage]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Duplicate decimal labels receive inconsistent normalization.
- ⚠️ SQL Lab result values can differ by column order.
- ⚠️ Chart metadata and displayed numeric values may be incorrect.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=4bf479a383734ebd8cab9b48dbbab181&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=4bf479a383734ebd8cab9b48dbbab181&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/mysql.py
**Line:** 251:254
**Comment:**
*Incorrect Variable Usage: Adding the `NEWDECIMAL` mapping activates
the decimal mutator for MySQL result sets, but the mutator bookkeeping is keyed
by column name rather than column position. Queries with duplicate labels, such
as selecting two expressions both aliased as `amount`, can therefore omit
conversion of the first decimal column or apply conversion to the wrong
occurrence depending on the order and types of the duplicate columns. Track
mutators by description index so every matching result column is handled
independently.
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%2F42821&comment_hash=a3e15475da74b6439f9f73ad6289d29377a5d0c555ae5755d65701ceab8857f2&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42821&comment_hash=a3e15475da74b6439f9f73ad6289d29377a5d0c555ae5755d65701ceab8857f2&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]