Skip to content

Remove documented template variables that no default template uses - #3098

Merged
simonw merged 1 commit into
mainfrom
remove-unused-template-variables
Nov 22, 2026
Merged

simonw merged 1 commit into
mainfrom
remove-unused-template-variables

Conversation

@simonw

@simonw simonw commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Closes:

The template context documentation promises that documented variables are stable until Datasette 2.0. This removes the documented variables that none of the default templates use and that nothing else was found to depend on, so they are not frozen by 1.0.

Claude Fable 5.2 Medium

Removed

Variable Pages Why
ok table, row, stored query list, error A JSON API field that leaked into the template context. Constant on each page.
ok save query, edit query Same as analysis_error is None, and analysis_error is what the templates use.
parameters save query, edit query Neither template renders parameter inputs.
path database Duplicates urls.database(database).
editable database Hard-coded True, and documented incorrectly. The real editable on the query page is unchanged.
queries_more database Derivable from queries_count and queries.
page_size homepage Always 30.
limit stored query list The template uses start, total and queries.
show_private_note, show_trusted_note stored query list Unused since the page was redesigned.
show_database stored query list Same as database is none.

Kept on purpose

These are also unused by the default templates, but are now on an allow-list in the new test with the reason for each:

  • url_csv (table, row, query): custom templates based on older default templates link to it.
  • columns (table, row): render_template() passes it to the extra_body_script, extra_template_vars, extra_css_urls and extra_js_urls plugin hooks.
  • rows (table, row): the raw values; display_rows only has rendered cells.
  • next (table, stored query list): the pagination token.
  • count_sql (table): matches ?_extra=count_sql.
  • base_url (every page): used by templates in plugins.

JSON API

Unchanged, with one exception: /-/queries.json and /<database>/-/queries.json no longer return show_private_note and show_trusted_note. They existed only for the old HTML page and those endpoints are not documented. ok, limit, show_database, path and queries_more are still returned by the JSON endpoints that had them.

Test

tests/test_template_context.py gains test_documented_variables_are_used_by_default_templates and test_base_context_variables_are_used_by_default_templates. They parse each documented page's template and everything it includes with jinja2.meta, and fail if a documented variable is not used by any default template unless it is on the allow-list. The check runs in both directions, so an allow-listed variable that starts being used also fails.

Checked

  • Full test suite: 3482 passed.
  • black, ruff and cog --check clean; docs/template_context.rst regenerated with cog.

For review

  • parameters, queries_more and count_sql were the close calls. count_sql is kept and the other two removed; either is easy to flip.
  • Dropping the two show_*_note keys from the queries JSON is the only change outside the template context.

🤖 Generated with Claude Code

Removes ok, path, editable, queries_more, page_size, limit,
show_private_note, show_trusted_note, show_database and parameters from
the template contexts where no default template uses them, so they are
not frozen by the template context stability promise.

Keeps url_csv, count_sql, rows, columns, next and base_url, which custom
templates and plugins rely on, and adds a test with an allow-list so a
documented variable that no template uses has to be listed on purpose.

Closes #3088

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@simonw simonw added this to the Datasette 1.0 stable milestone Nov 21, 2026
@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (ec96e4e) to head (c9772b0).

Files with missing lines Patch % Lines
datasette/views/query_helpers.py 0.00% 2 Missing ⚠️
datasette/views/stored_queries.py 0.00% 2 Missing ⚠️
datasette/handle_exception.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main   #3098   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         80      80           
  Lines      14301   14289   -12     
=====================================
+ Misses     14301   14289   -12     

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

@simonw
simonw merged commit c89a129 into main Nov 22, 2026
16 checks passed
@simonw
simonw deleted the remove-unused-template-variables branch November 22, 2026 20:10
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.

1 participant