Skip to content

Drop format_bytes in favor of Jinja's filesizeformat filter - #3078

Merged
simonw merged 2 commits into
mainfrom
drop-format-bytes
Nov 16, 2026
Merged

simonw merged 2 commits into
mainfrom
drop-format-bytes

Conversation

@simonw

@simonw simonw commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Refs:

format_bytes() duplicated Jinja's built-in filesizeformat filter. The homepage already used the filter, so the homepage and the database page showed different sizes for the same database file. Every size now goes through filesizeformat.

Claude Fable 5.2 Medium

Backwards incompatible

  • format_bytes() is removed from the template context, where it was a documented variable, and from datasette.utils. Custom templates should use {{ size|filesizeformat }}.
  • Sizes now use decimal units, so the displayed values change:
Bytes Before After
120 120 bytes 120 Bytes
1,023 1023 bytes 1.0 kB
20,000 19.5 KB 20.0 kB
5,242,880 5.0 MB 5.2 MB

Changes

  • database.html uses {{ size|filesizeformat }} for the summary line and the download button.
  • The binary value tooltips in views/table.py and views/database.py call jinja2.filters.do_filesizeformat. The tooltip is skipped for values under 1,000 bytes; it was previously skipped when the formatted string contained "bytes".
  • Removed the function, its template context entry, its test and its entry in docs/template_context.rst.
  • Added an Unreleased changelog section covering both changes.

🤖 Generated with Claude Code

simonw and others added 2 commits November 15, 2026 20:33
format_bytes() duplicated a filter Jinja already ships, and the
homepage was already using that filter, so the homepage and the
database page disagreed about the size of the same file. Sizes now
all use filesizeformat, which means decimal units: 1 MB is 1,000,000
bytes, not 1,048,576.

format_bytes is removed from datasette.utils and from the template
context. Custom templates should use {{ size|filesizeformat }}.

Refs #1841

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

codecov Bot commented Nov 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (51badf9) to head (05287e7).

Files with missing lines Patch % Lines
datasette/views/database.py 0.00% 2 Missing ⚠️
datasette/views/table.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main   #3078   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         79      79           
  Lines      13981   13974    -7     
=====================================
+ Misses     13981   13974    -7     

☔ 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 linked an issue Nov 16, 2026 that may be closed by this pull request
@simonw
simonw merged commit 6c6120c into main Nov 16, 2026
15 checks passed
@simonw
simonw deleted the drop-format-bytes branch November 16, 2026 04:38
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.

Drop format_bytes for Jinja filesizeformat filter

1 participant