- 
                Notifications
    
You must be signed in to change notification settings  - Fork 16.1k
 
fix(mysql): render TINYINT(1) columns as boolean in SQL Lab and charts #35297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Fixes MySQL TINYINT(1)/BOOLEAN columns displaying as numeric icons with 0/1 values instead of boolean representation with True/False in SQL Lab and Explore views. ## Changes ### Schema Mapping (mysql.py) - Add precise column_type_mappings for TINYINT(1), BOOLEAN, and BOOL patterns - Map to GenericDataType.BOOLEAN for proper metadata inspection - Ensures dataset schemas show boolean icons for actual boolean types only ### Runtime Conversion (mysql.py) - Implement fetch_data override with ultra-precise boolean detection - Convert 0/1 integers to True/False for TINYINT(1) columns - Use multiple reliable markers: FIELD_TYPE.TINY + display_size=1 OR SQLAlchemy type string - Extract _is_boolean_column helper method for clean detection logic - Enables pandas boolean dtype inference via extract_dataframe_dtypes ### Testing (test_mysql.py) - Add boolean type test cases to existing parametrized tests - Test TINYINT(1), BOOLEAN, BOOL → boolean mapping - Test TINYINT, TINYINT(2+) → numeric mapping (preserved behavior) ## Technical Details MySQL stores BOOLEAN as TINYINT(1) but returns 0/1 integers instead of Python booleans. This two-layer solution: 1. Maps TINYINT(1) metadata to GenericDataType.BOOLEAN for schema inspection 2. Converts query result values 0/1 → True/False for proper pandas inference The detection uses explicit width 1 or positive SQLAlchemy type string markers to avoid mis-converting broader TINYINT columns. Fixes: #35166 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
…ersion
- Fix critical bug where bool('0') and bool(b'0') returned True instead of False
- Add proper type normalization for strings, bytes, and Decimal values
- Convert string/bytes/Decimal to int before applying bool() for accurate MySQL boolean conversion
- Maintains existing behavior for integer values while fixing edge cases
- Addresses feedback on conversion logic in mysql.py:323-330
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
| Category | Issue | Status | 
|---|---|---|
| Unreliable boolean column detection across drivers ▹ view | 🧠 Not in standard | 
Files scanned
| File Path | Reviewed | 
|---|---|
| superset/db_engine_specs/mysql.py | ✅ | 
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
| # 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)"]) | 
      
        
              This comment was marked as resolved.
        
          
      
    
    This comment was marked as resolved.
Sorry, something went wrong.
| value = int(value) | ||
| elif isinstance(value, Decimal): | ||
| value = int(value) | ||
| new_row[col_idx] = bool(value) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a perfect case for column_type_mutators, see https://github.com/apache/superset/blob/master/superset/db_engine_specs/base.py#L342-L344 and https://github.com/apache/superset/blob/master/superset/db_engine_specs/base.py#L993-L998
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless @betodealmeida can think of a better way
SUMMARY
Root Cause
MySQL boolean fields were incorrectly displaying as numeric icons with raw 0/1 values instead of readable True/False text in SQL Lab and Explore views. The issue had two layers:
Solution
Two-layer fix targeting MySQL's TINYINT(1) boolean representation:
Changes
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION