Fix infinite loop when streaming CSV on SQL views, fixes #2902 (#2903)

When streaming a view as CSV with ?_stream=on, _next was being
re-read from request.args, overwriting the kwarg passed by the
streaming loop with None. This caused the pagination offset to stay
stuck on page 1 forever.
This commit is contained in:
AnkitaAdvitot 2026-09-16 01:27:09 +05:30 committed by GitHub
commit 920adc6880
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View file

@ -2312,8 +2312,6 @@ async def table_view_data(
new_rows.append(new_row)
rows = new_rows
_next = request.args.get("_next")
# Pagination next link
next_value, next_url = await _next_value_and_url(
datasette,

View file

@ -229,6 +229,20 @@ async def test_table_csv_stream(ds_client):
assert len([b for b in response.content.split(b"\r\n") if b]) == 1002
@pytest.mark.asyncio
async def test_view_csv_stream(ds_client):
# Without _stream should return header + 100 rows:
response = await ds_client.get("/fixtures/paginated_view.csv?_size=max")
assert len([b for b in response.content.split(b"\r\n") if b]) == 101
# With _stream=1 should paginate through all pages and return header + 202 rows
response = await ds_client.get("/fixtures/paginated_view.csv?_stream=1")
lines = [b for b in response.content.split(b"\r\n") if b]
assert len(lines) == 203
# Ensure there are no duplicate rows from looping
assert len(set(lines[1:])) == 202
assert lines[0] == b"content,content_extra"
def test_csv_trace(app_client_with_trace):
response = app_client_with_trace.get("/fixtures/simple_primary_key.csv?_trace=1")
assert response.headers["content-type"] == "text/html; charset=utf-8"