korbit-ai[bot] commented on code in PR #35297:
URL: https://github.com/apache/superset/pull/35297#discussion_r2380054743


##########
superset/db_engine_specs/mysql.py:
##########
@@ -260,6 +272,67 @@ def get_datatype(cls, type_code: Any) -> Optional[str]:
     def epoch_to_dttm(cls) -> str:
         return "from_unixtime({col})"
 
+    @classmethod
+    def _is_boolean_column(cls, col_desc: tuple[Any, ...]) -> bool:
+        """Check if a cursor column description represents a boolean column."""
+        type_code = col_desc[1] if len(col_desc) > 1 else None
+        display_size = col_desc[2] if len(col_desc) > 2 else None
+
+        # Only process FIELD_TYPE.TINY (type_code 1)
+        if type_code != 1:
+            return False
+
+        # Explicit width 1 indicates TINYINT(1)/BOOLEAN
+        if display_size == 1:
+            return True
+
+        # Check SQLAlchemy type string (some drivers provide it at index 4)
+        if len(col_desc) > 4 and isinstance(col_desc[4], str):
+            sqla_type_str = col_desc[4].lower()
+            return any(marker in sqla_type_str for marker in ["bool", 
"tinyint(1)"])

Review Comment:
   ### Unreliable boolean column detection across drivers <sub>![category 
Functionality](https://img.shields.io/badge/Functionality-0284c7)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The code assumes cursor.description[4] contains SQLAlchemy type information, 
but this is not guaranteed across different MySQL drivers and may cause 
incorrect boolean column detection.
   
   
   ###### Why this matters
   Different MySQL drivers (MySQLdb, PyMySQL, mysql-connector-python) have 
different cursor.description formats. Relying on index 4 for type information 
may lead to false positives or missed boolean columns, resulting in incorrect 
data type handling.
   
   ###### Suggested change ∙ *Feature Preview*
   Remove the unreliable driver-specific check and rely only on the 
standardized type_code and display_size:
   
   ```python
   @classmethod
   def _is_boolean_column(cls, col_desc: tuple[Any, ...]) -> bool:
       """Check if a cursor column description represents a boolean column."""
       type_code = col_desc[1] if len(col_desc) > 1 else None
       display_size = col_desc[2] if len(col_desc) > 2 else None
   
       # Only process FIELD_TYPE.TINY (type_code 1)
       if type_code != 1:
           return False
   
       # Explicit width 1 indicates TINYINT(1)/BOOLEAN
       return display_size == 1
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice 
Catch](https://img.shields.io/badge/👍%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/85cdc8ff-3690-4ad8-a01e-a065e06cb5c9/upvote)
 
[![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/85cdc8ff-3690-4ad8-a01e-a065e06cb5c9?what_not_true=true)
  [![Not in 
Scope](https://img.shields.io/badge/👎%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/85cdc8ff-3690-4ad8-a01e-a065e06cb5c9?what_out_of_scope=true)
 [![Not in coding 
standard](https://img.shields.io/badge/👎%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/85cdc8ff-3690-4ad8-a01e-a065e06cb5c9?what_not_in_standard=true)
 
[![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/85cdc8ff-3690-4ad8-a01e-a065e06cb5c9)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:13b58795-cb3f-43e5-9312-ec5d320ab30c -->
   
   
   [](13b58795-cb3f-43e5-9312-ec5d320ab30c)



-- 
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