Skip to content

fix(run): refuse negative --max-rows before querying (#119) - #121

Merged
laaielichter merged 4 commits into
laaielichter:mainfrom
dianatofficial:fix/run-max-rows-validation
Nov 15, 2026
Merged

laaielichter merged 4 commits into
laaielichter:mainfrom
dianatofficial:fix/run-max-rows-validation

Conversation

@dianatofficial

Copy link
Copy Markdown
Contributor

Fixes #119.

What was wrong

gulliver run --max-rows N silently clamped negative values to 0 (max(0, min(int(max_rows), ...))), returning an empty preview: [] with status: "ok" instead of failing loudly.

What changed

  • Validated max_rows at the top of run() in src/gulliver/core.py: when max_rows is not None and is negative (< 0), boolean, or non-integer, run() returns _error(...) naming the flag and invalid value alongside a clear next_step, exiting with code 1 before running preflight/estimation, touching the database, or writing a receipt.
  • --max-rows 0 (row counts without preview rows), values above budget.max_output_rows (still capped to budget), and omitted max_rows (None) continue to behave identically to before.
  • Note for Python callers: rejecting bool / non-int floats is slightly stricter than the old int(max_rows) coercion.
  • Added unit tests in tests/test_flow_duckdb.py (testing max_rows=-5 writes no receipt, max_rows=0, and capping above max_output_rows) and CLI tests in tests/test_cli_and_mcp.py (--json and plain output).
  • Added a CHANGELOG.md entry under Unreleased -> Fixed.

Verification

  • ruff check .: All checks passed!
  • pytest -q -k "not symlink": 851 passed, 11 skipped, 3 deselected on Windows 11 with Python 3.13 (the 3 deselected tests in tests/test_security.py call os.symlink).

@laaielichter laaielichter left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dianatofficial, #119 is assigned to you (your claim at 08:26 was the only one) and the PR does what the issue asks. One small CHANGELOG move and it is ready.

What I checked. I merged 6f863ea onto current main (986a194) in a scratch worktree: clean merge, ruff check . passes, pytest -q gives 855 passed, 10 skipped (no symlink tests deselected needed on Linux). Against #119's "Done when":

  • run() validates max_rows before anything is estimated or executed, so Python callers get it too, and --max-rows -5 returns status: "error" naming the value with a next_step, exit code 1, and list_receipts stays empty.
  • --max-rows 0, a value above max_output_rows (still capped) and leaving the option out behave as before.
  • Tests exist through core.run() and through main([...]) (JSON and plain output), plus the 0 case.
  • Rejecting booleans and non-integers is a bit stricter than the old int(max_rows); that is fine, the MCP tool already types it as an int.

Please fix: where the CHANGELOG line sits. The new bullet is at the top of ### Fixed. Other open PRs also add their line at the top of that list, so they will all conflict. Please move your bullet to the end of the existing ### Fixed list (just above ### Changed), then push.

Optional. Both test files end with an extra blank line; you can drop it while you are in there.

CI: both runs for this commit (ci, codeql) are action_required, which is GitHub holding a new contributor's first run until a maintainer approves it, so no check has run yet.


Generated by Claude Code

@dianatofficial

Copy link
Copy Markdown
Contributor Author

Moved the \CHANGELOG.md\ bullet to the end of ### Fixed\ (just above ### Changed) and removed the extra trailing blank lines in both test files.
uff check .\ and both test modules pass.

@laaielichter laaielichter left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @dianatofficial, both things from my last review are done in 8f965cc: the #119 bullet is now at the end of ### Fixed (just above ### Changed), and the extra blank lines at the end of the two test files are gone.

What I checked. I merged 8f965cc onto current main (c48adf8) in a scratch worktree: clean merge (the CHANGELOG no longer conflicts), ruff check . passes, pytest -q gives 873 passed, 10 skipped. The code and tests are unchanged from 6f863ea, which I already checked against #119's "Done when", so nothing else to add.

CI: both runs for this commit (ci, codeql) are action_required, which is GitHub holding a first-time contributor's run until a maintainer approves it, so no check has run on GitHub yet.


Generated by Claude Code

Copy link
Copy Markdown
Owner

@dianatofficial #105 just merged, so CHANGELOG.md and tests/test_cli_and_mcp.py now conflict with this PR (both add lines at the end). Could you merge or rebase main into your branch and keep both blocks? The code is approved, so it can merge as soon as the branch is updated and CI is green.


Generated by Claude Code

@dianatofficial

dianatofficial commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Resolved the \ ests/test_cli_and_mcp.py\ merge locally and verified
uff check .\ + tests pass, though pushing \upstream/main's
elease.yml\ diff from my current CLI OAuth token hit a \workflow\ scope rejection — pushing shortly once synced via web/auth refresh.

Copy link
Copy Markdown
Owner

Thank you, @dianatofficial! I don't see the merge on the PR yet, though: its head is still 8f965cc and GitHub still reports a conflict with main. Could the push have gone to a different branch or failed? It needs to go to fix/run-max-rows-validation on your fork (git push origin fix/run-max-rows-validation). As soon as it is there and CI is green, I will merge it.


Generated by Claude Code

Copy link
Copy Markdown
Owner

@dianatofficial a small tip in case the workflow scope rejection is still what blocks the push: main now contains a change to .github/workflows/release.yml, and GitHub refuses a push that carries workflow files unless the token has the workflow scope. Two ways around it: use the Update branch button on this PR page (it merges main for you, but then please check that the conflict in CHANGELOG.md / tests/test_cli_and_mcp.py is resolved, since the button only works when there is no conflict), or refresh your token with gh auth refresh -s workflow and push again. The head is still 8f965cc, so once it moves I will re-check and merge when CI is green. Thanks for sticking with it!


Generated by Claude Code

@dianatofficial

Copy link
Copy Markdown
Contributor Author

@laaielichter Merged current main into the branch, kept both test blocks in ests/test_cli_and_mcp.py, and verified the #119 bullet sits cleanly at the end of ### Fixed under ## Unreleased. All conflicts are resolved and the branch is clean and ready to land. Thank you!

@laaielichter laaielichter left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @dianatofficial for merging main in. Still approved on f8cfa4e.

Compared with 8f965cc, which I approved, the only change is the merge of current main (52666d3); the code, the tests and the CHANGELOG line for #119 are the same, and the merge is clean. With this head: ruff check . passes, git diff --check is clean and pytest -q gives 887 passed, 10 skipped.

CI: the ci and codeql runs for this head are action_required until a maintainer approves them, and Gulliver needs all 14 checks green, so I am not merging yet.


Generated by Claude Code

Copy link
Copy Markdown
Owner

@dianatofficial a heads-up: other PRs landed on main today and added their CHANGELOG lines in ## Unreleased, right where this PR adds its own, so this PR now conflicts with main in that file. Could you merge main into your branch and keep all the lines (yours at the end of the list)? The code stays approved and CI was green on this head. After the merge, the CI runs wait for the maintainer's approval once more.


Generated by Claude Code

@dianatofficial

Copy link
Copy Markdown
Contributor Author

@laaielichter Merged current main into the branch and kept all CHANGELOG lines with our entry at the end of the Fixed list as requested. All conflicts are resolved and the branch is clean. Thank you!

@laaielichter laaielichter left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @dianatofficial for merging the current main in again. Still approved, now on 41ee698.

Compared with what I approved earlier, your change is the same: run() validation in core.py, the two test files and the #119 CHANGELOG line (the merge of main resolved the CHANGELOG cleanly; the branch is now 0 commits behind main bff74d0). With this head: ruff check . passes, git diff --check is clean and pytest -q gives 976 passed, 10 skipped.

By hand: on main, gulliver run --max-rows -5 "SELECT 1" runs and writes a receipt; on this head it returns status: error ("--max-rows must be at least 0, got -5.") with a next_step, before anything is queried. Mutation check: with core.py reverted to main, test_run_refuses_negative_max_rows_and_allows_zero and test_cli_run_refuses_negative_max_rows_and_allows_zero both fail, so the tests do guard the fix.

I have approved the ci and codeql runs for this head; the PR merges once all 14 required checks are green.


Generated by Claude Code

@laaielichter
laaielichter merged commit 5d9b46a into laaielichter:main Nov 15, 2026
14 checks passed
laaielichter added a commit that referenced this pull request Nov 15, 2026

Copy link
Copy Markdown
Owner

Merged as 5d9b46a, all 14 checks green. Thank you @dianatofficial for sticking with this one through three rounds of main moving under it: the validation is small, correct, and tested through both core.run() and the CLI. The credit line is in the CHANGELOG (#176). With #121 merged you hold two open issues (#112 and #152), so you can claim one more as soon as you like; finishing and merging #115 and #168 is the quickest way to free the rest.


Generated by Claude Code

laaielichter added a commit that referenced this pull request Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

run --max-rows: a negative number quietly returns an empty preview and reports ok

2 participants