aminghadersohi opened a new pull request, #36599:
URL: https://github.com/apache/superset/pull/36599
## Summary
Fixes a bug where CTE (Common Table Expression) queries using `WITH ... AS
... SELECT` syntax were returning empty `rows` in the MCP `execute_sql` tool
response, even though the query executed successfully.
**Root Cause**: The `_is_select_query()` function only checked for queries
starting with `SELECT`, but CTE queries start with `WITH`. This caused CTEs to
be incorrectly routed to `_process_dml_results()` instead of
`_process_select_results()`.
**Symptoms**:
- CTE queries return `rows: []` but correct `affected_rows`
- Equivalent subqueries work fine
- Example: `WITH simple AS (SELECT 'test' as val) SELECT val FROM simple` →
empty rows
## Changes
- Updated `_is_select_query()` to recognize `WITH` clauses as SELECT-like
queries
- Updated `_apply_limit()` to add LIMIT to CTE queries
- Added 18 comprehensive unit tests for CTE query handling
## Testing Instructions
```python
# Before fix: returns {"rows": [], "affected_rows": 1}
# After fix: returns {"rows": [{"val": "test"}], "row_count": 1}
WITH simple AS (SELECT 'test' as val) SELECT val FROM simple
```
Run unit tests:
```bash
pytest tests/unit_tests/mcp_service/sql_lab/test_sql_lab_utils.py -v
```
## Additional Information
- [x] Unit tests added
- [x] No breaking changes
- [x] Follows conventional commits
--
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]