Skip to content

?_stream=1 uses smaller pages after a timeout - #3092

Merged
simonw merged 2 commits into
mainfrom
claude/great-curie-d1ol9r
Nov 20, 2026
Merged

simonw merged 2 commits into
mainfrom
claude/great-curie-d1ol9r

Conversation

@simonw

@simonw simonw commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to #3070, which fixes a regression it introduced.

Since #3070, ?_stream=1 fetches pages of max_returned_rows (1,000 by default), and each page still has to finish inside sql_time_limit_ms. A table or view that is slow to compute now returns a 500 QueryInterrupted, or drops the connection if a later page is the slow one.

  • A streamed page that is interrupted is fetched again using the default page size, capped at max_returned_rows. That size is used for the rest of the stream.
  • A ?_size= in the URL still sets the page size and gets the error.
  • max_returned_rows of 0 (no limit) streamed no rows. It now uses the default page size.

Tests: 11 new cases in tests/test_renderer_streaming.py, 7 of which fail without the fix. The full suite passes. Checked by hand against a view costing about 2ms a row: a 500 on main, all 2,000 rows with this change.

A stream that falls back waits up to sql_time_limit_ms once before it retries.

The only docs change is that row_stream.pages() pages are now described as "up to" max_returned_rows rows.

🤖 Generated with Claude Code

https://claude.ai/code/session_016BvfqDPa3tXaNL3aFk4eYj

Streaming fetches pages of max_returned_rows, and each page still has
to finish inside sql_time_limit_ms. A table or view that was slow to
compute could be streamed at 100 rows a page but returned a 500
QueryInterrupted at 1,000, or dropped the connection if a later page
was the slow one.

A page that is interrupted is now fetched again using the default page
size, which is then used for the rest of the stream. That size is
capped at max_returned_rows, because a longer page is cut short with
no next page. A ?_size= in the URL still sets the size and gets the
error.

Also fixes max_returned_rows of 0, which means no limit: streaming
used it as the page size and returned no rows.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016BvfqDPa3tXaNL3aFk4eYj
@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (1770c90) to head (86d3a5c).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
datasette/views/table.py 0.00% 19 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main   #3092   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         80      80           
  Lines      14282   14301   +19     
=====================================
- Misses     14282   14301   +19     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The docs now only say that streamed pages are up to max_returned_rows
rows each.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016BvfqDPa3tXaNL3aFk4eYj
Comment thread docs/plugin_hooks.rst Outdated
``row_stream`` yields the rows on the current page. If the URL includes ``?_stream=1`` it carries on past the end of that page, fetching one page at a time, until it has yielded every row in the table or view. Your function does not need to know which of those is happening.

Use ``async for rows in row_stream.pages()`` to receive a list of rows for each page instead of one row at a time. When streaming every row those pages are :ref:`setting_max_returned_rows` rows each, unless the URL sets a different ``?_size=``.
Use ``async for rows in row_stream.pages()`` to receive a list of rows for each page instead of one row at a time. When streaming every row those pages are up to :ref:`setting_max_returned_rows` rows each, unless the URL sets a different ``?_size=``. If fetching a page that size takes longer than :ref:`setting_sql_time_limit_ms`, that page and the ones after it use the default page size instead.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Documentation is too thorough.

@simonw
simonw merged commit b866054 into main Nov 20, 2026
12 of 13 checks passed
@simonw
simonw deleted the claude/great-curie-d1ol9r branch November 20, 2026 03:08
@simonw simonw added the bug label Nov 20, 2026
@simonw simonw added this to the Datasette 1.0 stable milestone Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants