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

   ### SUMMARY
   `list_charts`, `list_datasets`, and `list_dashboards` (MCP service tools) 
rejected `order_column=changed_on_delta_humanized` with `Invalid order_column 
'...'`, even though `changed_on_delta_humanized` is the exact column name 
Superset's own REST API and list views use for "Last modified" (see 
`order_columns` in `charts/api.py`, `datasets/api.py`, `dashboards/api.py`). 
Any caller — human or LLM agent — that copies that column name to sort by "most 
recently modified" gets an error.
   
   `changed_on_delta_humanized` is a computed/humanized rendering of 
`changed_on` (bound via Flask-AppBuilder's `@renders("changed_on")` in 
`models/helpers.py`), not a real queryable SQLAlchemy column, so it can't 
simply be passed straight through to the DAO's `ORDER BY`.
   
   This PR:
   - Adds `changed_on_delta_humanized` to the `CHART_SORTABLE_COLUMNS`, 
`DATASET_SORTABLE_COLUMNS`, and `DASHBOARD_SORTABLE_COLUMNS` allowlists in 
`superset/mcp_service/common/schema_discovery.py`, so it's accepted and 
advertised as sortable (matching REST API behavior and precedent already 
established in `daos/datasource.py`'s `sort_col_map`).
   - Resolves the alias to the real `changed_on` column in 
`ModelListCore.run_tool` (`superset/mcp_service/mcp_core.py`) before the DAO 
call, since `BaseDAO.list()` sorts via `getattr(model, order_column)` and would 
otherwise receive a Python method instead of a SQL column.
   - Leaves `_validate_order_column` rejecting genuinely unknown columns 
unchanged — only the declared alias is special-cased.
   - Updates the three tools' docstrings to document the accepted alias.
   
   ### TESTING INSTRUCTIONS
   - Added unit tests in 
`tests/unit_tests/mcp_service/system/tool/test_mcp_core.py` covering the alias 
resolution and confirming unrelated unknown columns still raise.
   - Added regression tests in 
`tests/unit_tests/mcp_service/chart/tool/test_list_charts.py`, 
`tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py`, and 
`tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_tools.py` asserting 
`order_column=changed_on_delta_humanized` is accepted and resolves to 
`changed_on` for each of the three list tools, plus that an unknown 
`order_column` (e.g. `random`) still raises a `ToolError`.
   - Verified the new tests fail against the pre-fix code (reproducing the 
reported `ValueError: Invalid order_column 'changed_on_delta_humanized'`) and 
pass with the fix.
   - `uvx pre-commit run --files <changed files>` passes (mypy, ruff, 
ruff-format, pylint).
   
   ### ADDITIONAL INFORMATION
   - [ ] 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