YuriyKrasilnikov commented on PR #37371:
URL: https://github.com/apache/superset/pull/37371#issuecomment-3789425390

   ## Full Analysis: `{"column": "country"}` format does not exist
   
   We traced all data flows to verify if the proposed bug scenario can occur.
   
   ---
   
   ### 1. Type Definitions (superset/superset_typing.py)
   
   ```python
   # Line 116
   OrderBy = tuple[Metric | Column, bool]   # Note: bool, not string "desc"
   
   # Line 114-115
   Column = AdhocColumn | str
   Metric = AdhocMetric | str
   
   # Lines 51-57
   class AdhocMetric(TypedDict, total=False):
       aggregate: str
       column: AdhocMetricColumn | None     # ← DICT or None, never string
       expressionType: Literal["SIMPLE", "SQL"]
       hasCustomLabel: bool | None
       label: str | None
       sqlExpression: str | None
   
   # Lines 37-48
   class AdhocMetricColumn(TypedDict, total=False):
       column_name: str | None              # ← Nested dict with column_name
       description: str | None
       expression: str | None
       ...
   ```
   
   **Type conclusion:** `AdhocMetric.column` is `AdhocMetricColumn` (dict) or 
`None`, never a plain string.
   
   ---
   
   ### 2. API Entry Points
   
   | Entry Point | File:Lines | Format |
   |-------------|------------|--------|
   | POST /api/v1/chart/data | charts/data/api.py:193-285 | JSON → 
QueryContextFactory |
   | GET /api/v1/chart/{id}/data | charts/data/api.py:72-191 | Saved chart → 
QueryContextFactory |
   | Schema validation | charts/schemas.py:1345-1363 | 
`fields.List(fields.Tuple((fields.Raw(), fields.Boolean())))` |
   | QueryObject init | query_object.py:127,151 | `orderby: list[OrderBy]` |
   | QueryContextFactory | query_context_factory.py:74-86 | Passes via **kwargs 
|
   
   ---
   
   ### 3. Frontend Components Analysis
   
   | Component | File:Line | Actual Format |
   |-----------|-----------|---------------|
   | Table Chart sortBy | plugin-chart-table/src/buildQuery.ts:240 | 
`[[sortByItem.key, bool]]` where key is **string** |
   | Table SortByItem type | plugin-chart-table/src/types.ts:119-123 | `{id: 
string, key: string, desc?: boolean}` |
   | Filter Select | filters/components/Select/buildQuery.ts:63-66 | 
`sortColumns.map(column => [column, bool])` where column is **string** |
   | MatrixifyControl | explore/.../fetchTopNValues.ts:57 | `[[metric, bool]]` 
where metric is **string** |
   | DndMetricSelect | explore/.../DndMetricSelect.tsx:358 | `column: 
itemValue` where itemValue is `ColumnMeta` (**dict** with column_name) |
   
   **Frontend conclusion:** orderby is always `[[string, bool]]` or 
`[[AdhocMetric_with_column_as_dict, bool]]`. Never `{"column": "string"}`.
   
   ---
   
   ### 4. Data Flow Trace
   
   ```
   HTTP Request (JSON body)
       ↓
   ChartDataRestApi.data() [api.py:193]
       ↓
   json_body = request.json [api.py:244-248]
       ↓
   _create_query_context_from_form(json_body) [api.py:253]
       ↓
   ChartDataQueryContextSchema().load() [api.py:546]
       ↓
   QueryContextFactory.create() [query_context_factory.py:74]
       ↓
   QueryObject(orderby=...) [query_object.py:151]
       ↓
   query_context_modified() [manager.py:372]
       ↓
   _orderby_whitelist_compare() [manager.py:285]
       ↓
   _extract_orderby_column_name(orderby_tuple[0]) [manager.py:301]
   ```
   
   At no point is `{"column": "string"}` created or transformed.
   
   ---
   
   ### 5. Problems with Proposed Test Case
   
   The example `form_data = {"orderby": [[{"column": "country"}, "desc"]]}` has 
two issues:
   
   1. **`"desc"` should be `bool`** — OrderBy type requires `tuple[..., bool]`, 
not `tuple[..., str]`
   2. **`{"column": "country"}` is invalid** — No TypedDict has this structure:
      - `AdhocMetric.column` = dict (AdhocMetricColumn) or None
      - `AdhocColumn` has no `column` field
      - Plain columns are strings `"country"`, not `{"column": "country"}`
   
   ---
   
   ### Conclusion
   
   The structure `{"column": "string_value"}` does not exist in the codebase:
   - Violates TypedDict contracts
   - Never generated by frontend
   - Never transformed from valid input
   - No code path creates this format
   
   Current implementation is correct per type definitions.


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