aminghadersohi opened a new pull request, #44604: URL: https://github.com/apache/superset/pull/44604
### SUMMARY SC-121813 This is a deliberate **contract change**, not a restoration of the documented behavior. The MCP `execute_sql` schema previously said: **"If specified, overrides any SQL LIMIT clause."** An explicit request `limit` is instead a safety cap: use the smaller of the last statement's outer SQL limit and the request limit, subject to the existing `SQL_MAX_ROW` clamp. A stricter SQL limit, including zero, must never be enlarged. - Root cause at base `8141d666`: `execute_sql` → `Database.execute` → `SQLExecutor._apply_limit_to_script` in `superset/sql/execution/executor.py:789` unconditionally called `set_limit_value`. This path has no `force` flag. - Use the parser's `get_limit_value` / `set_limit_value` APIs. Skip rewriting when the outer limit is already equal or smaller. Only the last statement is eligible; earlier statements, inner/CTE limits and offsets remain intact. - Preserve SC-100195's omitted-limit behavior from `d5cf77cd60beaa2b82b6dd2ed1cf50a70c0e2b77` (#38277): request `limit` defaults to `None`, leaving SQL limits unchanged. - Correct SQL Lab precedent: `superset/commands/sql_lab/execute.py:267` computes `min()` of SQL and request limits, then `superset/sql_lab.py:299` applies that result plus one for overfetch detection. SQL Lab's execution path does **not** use `Database.apply_limit_to_sql`. - Scope: the executor is shared by the public `Database.execute()` and `Database.execute_async()` APIs. Repository caller searches found no other non-MCP production callers. External API consumers also receive cap semantics, including dry runs; callers wanting more rows must explicitly increase/remove their SQL limit. Documented in `QueryOptions`, the MCP schema, admin docs and `UPDATING.md`. - No changes to authorization, non-destructive validation, dry-run handling, result-size guards or the existing `SQL_MAX_ROW` clamp. ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF No UI changes. | SQL outer limit | Request limit | Before | After | | --- | --- | --- | --- | | 5 | 10 | 10 | 5 | | 10 | 5 | 5 | 5 | | 5 | 5 | 5 | 5 | | 5 | omitted | 5 | 5 | | absent | 5 | 5 | 5 | | 0 | 10 | 10 | 0 | ### TESTING INSTRUCTIONS Local validation: ```bash PYTHONPATH="$PWD:$PWD/superset-core/src" pytest -q tests/unit_tests/sql/execution tests/unit_tests/mcp_service/sql_lab --disable-warnings PYTHONPATH="$PWD:$PWD/superset-core/src" pre-commit run ``` - **268 passed, 0 failed**, including 35 added cases. - Coverage: both cap directions, equal/omitted/absent limits, LIMIT 0, OFFSET, CTE/subquery inner limits, multi-statement scope, SQL_MAX_ROW, DB2's non-default WRAP_SQL method, sync/async dry runs, six real in-memory SQLite row-count cases, and the published MCP tool schema. - Pre-commit passed on the explicitly staged changed paths, including mypy, formatting, linting and Pylint. Manual verification on a local test database: call `execute_sql` with a read-only SELECT containing `LIMIT 5` and request `limit: 10`; confirm `executed_sql` retains 5 and `row_count <= 5`. Reverse the limits and verify 5; omit the request limit and verify the SQL limit is unchanged. Repeat with `dry_run: true` to inspect transformed SQL without execution. Staging reproduction and deployed revision remain **UNVERIFIED**. No Preset workspace was accessed or modified. ### ADDITIONAL INFORMATION - [x] Has associated issue: SC-121813 - [ ] 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]
