Skip to content

Show "more than N rows" in custom SQL heading when results are truncated - #3020

Open
pujitha24 wants to merge 1 commit into
simonw:mainfrom
pujitha24:auto/issue-3018
Open

pujitha24 wants to merge 1 commit into
simonw:mainfrom
pujitha24:auto/issue-3018

Conversation

@pujitha24

Copy link
Copy Markdown

Motivation: templates/query.html has a branch that renders "returning more
than N rows" when the result was cut off at max_returned_rows, but
truncated was never in the template context, so the HTML page showed
e.g. "returning 1,000 rows" for a truncated result. The JSON output already
reports truncated: true. The entry was lost when QueryContext replaced the
old context dict.

Approach: add a truncated field to QueryContext and pass
results.truncated if results else False (same expression already used
for the output renderers). Regenerated docs/template_context.rst with cog.

Impact: HTML heading text only; no change to the rows returned or to JSON.

Validation:

  • new test test_custom_sql_heading_says_more_than_when_truncated fails
    without the datasette/ change and passes with it
  • uv run pytest tests/test_html.py tests/test_docs.py tests/test_api.py
    (228 passed, 2 skipped, 2 xpassed)
  • black --check, ruff check on datasette/, cog -r docs/template_context.rst
    Full test suite was not run.

Report: #3018
Signed-off-by: Pujitha Paladugu 10557236+pujitha24@users.noreply.github.com
Assisted-by: claude-sonnet-5-5 (via Claude Code)

Fixes #3018

Motivation: templates/query.html has a branch that renders "returning more
than N rows" when the result was cut off at max_returned_rows, but
`truncated` was never in the template context, so the HTML page showed
e.g. "returning 1,000 rows" for a truncated result. The JSON output already
reports `truncated: true`. The entry was lost when QueryContext replaced the
old context dict.

Approach: add a `truncated` field to QueryContext and pass
`results.truncated if results else False` (same expression already used
for the output renderers). Regenerated docs/template_context.rst with cog.

Impact: HTML heading text only; no change to the rows returned or to JSON.

Validation:
- new test test_custom_sql_heading_says_more_than_when_truncated fails
  without the datasette/ change and passes with it
- uv run pytest tests/test_html.py tests/test_docs.py tests/test_api.py
  (228 passed, 2 skipped, 2 xpassed)
- black --check, ruff check on datasette/, cog -r docs/template_context.rst
Full test suite was not run.

Report: simonw#3018
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Assisted-by: claude-sonnet-5-5 (via Claude Code)

@chiragjangiir chiragjangiir left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review: Show "more than N rows" in custom SQL heading when truncated

1. UX Improvement

When executing custom SQL queries that exceed max_returned_rows (e.g. default 1000 rows), the table header previously stated "1,000 rows", potentially misleading users into believing the dataset contained exactly 1,000 rows rather than being truncated at the limit.

2. Implementation

  • Checks if row count equals max_returned_rows and truncated flag is True.
  • Displays "more than {max_returned_rows} rows" or "{max_returned_rows}+ rows" in template heading.
  • Cleanly integrates with Jinja2 template rendering in query.html.

3. Verdict

Valuable UX clarity enhancement for analytical users. LGTM!

This branch has not been deployed

No deployments
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.

Custom SQL page says "returning 1,000 rows" instead of "more than 1,000 rows" when the result is truncated

2 participants