Skip to content

Allow facet time limit to exceed SQL time limit, closes #1780 - #3129

Open
leo7martins wants to merge 3 commits into
simonw:mainfrom
leo7martins:fix/1780-facet-time-limit
Open

leo7martins wants to merge 3 commits into
simonw:mainfrom
leo7martins:fix/1780-facet-time-limit

Conversation

@leo7martins

@leo7martins leo7martins commented Nov 26, 2026 •

Copy link
Copy Markdown

Closes:

What was wrong

Facet.time_limit_ms returned capped_time_limit_ms(facet_time_limit_ms), so the effective limit for requested facets could never exceed sql_time_limit_ms. The facet_time_limit_ms setting was therefore silently capped at the main query's time limit, and the remaining gap noted in #1780 (after #3106) stayed in place: a facet that needs more time than the main query always timed out.

The fix

  • Facet.time_limit_ms now returns the facet_time_limit_ms setting directly, so requested facets can run longer than sql_time_limit_ms.
  • Facet suggestions remain capped: suggest_time_limit_ms still applies capped_time_limit_ms, now documented in docs/settings.rst.
  • The ?_timelimit= query string argument is unchanged and still capped for the main query.
  • Docs updated (docs/settings.rst) and changelog entry added.

How it was tested

  • python -m pytest tests/test_facets.py tests/test_api.py -q — 172 passed, 4 skipped, 1 xpassed.
  • python -m pytest -q (full suite) — 3921 passed, 201 skipped, 5 xfailed, 13 xpassed; 7 failed + 6 errors, all pre-existing on this Windows machine and reproduced identically on the unmodified base commit (cp1252 decoding in test_docs.py; timing-sensitive QueryInterrupted/span tests using single-digit-ms time limits). None are caused by this change.
  • New tests: test_facet_time_limit_can_exceed_sql_time_limit (ColumnFacet/ArrayFacet/DateFacet: requested limit uncapped, suggest limit capped), test_requested_facet_can_run_longer_than_sql_time_limit (recursive-CTE facet completes with sql_time_limit_ms=5, facet_time_limit_ms=30000), test_custom_sql_time_limit_cannot_exceed_setting (?_timelimit= still capped).

This was written with help from an AI coding assistant. The tests above were run by the assistant, not by a human.

@atishay-kasliwal atishay-kasliwal 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.

With sql_time_limit_ms=5 and facet_time_limit_ms=30000, a ColumnFacet over a 300k-row query now returns all three buckets (100000 each) in about 0.07 s; master capped it at 5 ms and reported it as timed out. Facet suggestions still use the 5 ms cap, and default-style settings give the same 200 ms limit as before.

leo7martins and others added 2 commits December 1, 2026 09:21
Co-authored-by: leo7martins <leo7martins@users.noreply.github.com>
@simonw simonw added the faceting label Dec 2, 2026
@codecov

codecov Bot commented Dec 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (94d713d) to head (74bae65).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
datasette/facets.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##            main   #3129    +/-   ##
======================================
  Coverage   0.00%   0.00%            
======================================
  Files         87      87            
  Lines      17387   17491   +104     
======================================
- Misses     17387   17491   +104     

☔ 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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants