richardfogaca opened a new issue, #37620:
URL: https://github.com/apache/superset/issues/37620

   ### Bug description
   
   Calculated columns (e.g., a `CASE` statement mapping countries to currency 
codes) do not appear in the **Currency code column** dropdown in the Dataset 
Editor, even though the dropdown is built from `allColumns` which includes both 
physical and calculated columns.
   
   ### Root cause
   
   In [`DatasourceEditor.jsx` (line 
1095–1096)](https://github.com/apache/superset/blob/master/superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.jsx#L1095-L1096),
 the dropdown options are filtered to only include columns where `type_generic 
=== GenericDataType.String`:
   
   ```js
   const stringColumns = allColumns
     .filter(col => col.type_generic === GenericDataType.String)
     .map(col => ({
       value: col.column_name,
       label: col.verbose_name || col.column_name,
     }));
   ```
   
   Calculated columns have `type_generic` set to `null` because the backend's 
`fetch_metadata()` only resolves type information for physical columns — 
calculated columns are added back to the dataset without type resolution. This 
causes the strict equality check to exclude every calculated column from the 
dropdown.
   
   ### Expected behavior
   
   Calculated columns should appear in the Currency code column dropdown. The 
currency formatting logic already handles invalid currency codes gracefully, so 
there is no risk in including columns whose `type_generic` is unresolved.
   
   ### Proposed fix
   
   Loosen the filter to include columns that either have `type_generic === 
GenericDataType.String` **or** have an `expression` (i.e., are calculated 
columns):
   
   ```js
   const stringColumns = allColumns
     .filter(col => col.type_generic === GenericDataType.String || 
col.expression)
     .map(col => ({
       value: col.column_name,
       label: col.verbose_name || col.column_name,
     }));
   ```
   
   No backend changes are needed.
   
   ### How to reproduce the bug
   
   1. Open a dataset in the Dataset Editor
   2. Go to the **Calculated Columns** tab and add a column (e.g., `CASE WHEN 
country = 'US' THEN 'USD' ELSE 'EUR' END`)
   3. Go back to the **Settings** tab and open the **Currency code column** 
dropdown
   4. Observe that the calculated column does not appear in the dropdown
   
   ### Screenshots/recordings
   
   _No response_
   
   ### Superset version
   
   master
   
   ### Python version
   
   Not applicable (frontend-only bug)
   
   ### Node version
   
   Not applicable
   
   ### Browser
   
   All
   
   ### Additional context
   
   - The `allColumns` array at line 1084 correctly includes calculated columns 
(spread from `databaseColumns` and `calculatedColumns`)
   - Calculated columns are identified by having a truthy `expression` property 
(line 627–630 of the same file)
   - The downstream currency formatting already guards against invalid codes, 
so this change is safe


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