massucattoj opened a new pull request, #42203:
URL: https://github.com/apache/superset/pull/42203

   ### SUMMARY
   
   Columns of MySQL virtual datasets (created from SQL Lab queries) showed a 
"?" type icon in the chart panel instead of ABC/#, which also hid 
type-dependent controls such as X-Axis Sort By.
   
   Physical datasets get column types from the SQLAlchemy inspector as DDL 
names (`VARCHAR(100)`, `DECIMAL(15,2)`), which match 
`MySQLEngineSpec.column_type_mappings`. Virtual dataset columns instead get 
their type from the driver's cursor description via `get_datatype`, which 
returns the raw wire-protocol `FIELD_TYPE` constant names (`VAR_STRING` for 
VARCHAR, `NEWDECIMAL` for DECIMAL, `TINY` for TINYINT, `BLOB` for TEXT, and so 
on). None of those names matched any mapping regex, so `type_generic` resolved 
to `None`.
   
   This PR adds mappings for the 8 wire-protocol names that had no match: 
`VAR_STRING`, `NEWDECIMAL`, `TINY`, `SHORT`, `BLOB`, `YEAR`, `ENUM` and `SET`. 
Regexes are anchored so they don't collide with existing DDL patterns (`^tiny$` 
vs `^tinytext`), and `^enum\b`/`^set\b` also cover the DDL forms 
(`ENUM('a','b')`), which were equally unresolved.
   
   Fixing the type resolution exposed a second, latent bug: MySQL registers a 
`column_type_mutators` entry that converts DECIMAL string values to Python 
`Decimal`, keyed on the resolved column type. It had never fired because 
`NEWDECIMAL` never resolved. Once it did, `BaseEngineSpec.fetch_data` crashed 
with `TypeError: 'tuple' object does not support item assignment`, because the 
mutation loop assigns rows back into the `fetchall()` result and mysqlclient 
returns a tuple of rows (psycopg2 returns a list, which is why the same code 
works for Postgres). Fixed by copying the result into a list before mutating.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <img width="1581" height="784" alt="Screenshot 2026-07-18 at 12 59 02" 
src="https://github.com/user-attachments/assets/63ac1ace-a257-4bf4-92eb-9a1948707fd4";
 />
   
   After:
   <img width="1497" height="837" alt="Screenshot 2026-07-18 at 12 59 27" 
src="https://github.com/user-attachments/assets/c31907a7-2392-43bd-a2c8-c2a4e77ed06c";
 />
   
   
   ### TESTING INSTRUCTIONS
   1. Start a MySQL instance and create a table exercising the affected types:
      ```sql
      CREATE TABLE sample_data (
        id INT AUTO_INCREMENT PRIMARY KEY,
        label VARCHAR(100),
        amount DECIMAL(15, 2)
      );
      INSERT INTO sample_data (label, amount) VALUES ('Ships', 10.50), 
('Planes', 22.30);
   2. Connect the MySQL database to Superset.
   3. In SQL Lab, run SELECT * FROM sample_data and use "Save or Overwrite 
Dataset" to save it as a new (virtual) dataset.
   4. Create a chart from that dataset.
   5. Verify label shows the string indicator, amount and id show the numeric 
indicator, and the chart renders data instead of a type error.
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


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