Repository navigation
Keep ui.number format display-only in sanitize() - #6550
Merged
falkoschindler merged 4 commits intoDec 2, 2026
Merged
Conversation
falkoschindler
self-requested a review
December 1, 2026 14:59
…ough the display The SQLite and reaktiv examples used `format` to round the age and the prices; now that `format` only affects the display, they get a matching `precision` so they keep storing what they show. The `format` docstring says so explicitly. The new test asserted on the private `model-value` prop. Instead, `test_apply_format_on_blur` now shows the unrounded value in a bound label next to the formatted input, and a `User` test covers the limit case from zauberzeug#6548 through `value` and `out_of_limits` only. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WgKVNb2aAsju6ryUWTWzky
This was referenced Dec 1, 2026
falkoschindler
previously approved these changes
Dec 1, 2026
falkoschindler
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @SHANNWD, this is exactly the fix the issue asked for: sanitize() now only clamps and rounds to precision, and format is display-only. I pushed a small follow-up commit onto your branch for the points below and brought the description onto our PR template, including the migration note for the release notes.
Addressed in b987018
- Two checked-in examples relied on
formatto round the stored value: the age inexamples/sqlite_database/main.pyand the prices inexamples/reaktiv/main.py. Withformatdisplay-only they would show "26" but store 25.7, so they now pass a matchingprecision, which is the migration the issue prescribes. - The
formatdocstring now says that the value itself is not rounded and points toprecision. - The new test asserted on the private
_props['model-value']. Per our guidelines tests assert observable behaviour, sotest_apply_format_on_blurnow shows the unrounded value in a bound label next to the formatted input, and aUsertest covers the limit case from #6548 throughvalueandout_of_limitsonly.
One thing I noticed along the way is out of scope here: format is a plain attribute, so changing it at runtime does not re-render the field. That is handled separately in #6553.
falkoschindler
enabled auto-merge
December 1, 2026 23:33
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Dec 1, 2026
Resolves the conflict with zauberzeug#6546 in `sanitize()`: the inward step after rounding stays, and the last line keeps `self.value = value` so the format is not written back into the value. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WgKVNYuqJYSmAQ5KHxKYPn
falkoschindler
previously approved these changes
Dec 2, 2026
falkoschindler
enabled auto-merge
December 2, 2026 00:14
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Dec 2, 2026
…anitize # Conflicts: # nicegui/elements/number.py
falkoschindler
approved these changes
Dec 2, 2026
falkoschindler
enabled auto-merge
December 2, 2026 07:44
falkoschindler
added a commit
that referenced
this pull request
Dec 2, 2026
Both sides appended a test to tests/test_number.py; the merge keeps test_format_does_not_round_the_value_below_the_minimum from #6550 followed by test_changing_format. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WgKVNZ3csUJiybGywqbjcv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Fixes #6548.
ui.number'sformatparameter is documented as formatting the displayed value, which_value_to_model_valuealready handles. However,Number.sanitize()ended withself.value = float(self.format % value) if self.format else value, writing the formatted string back intoself.valueon blur and whenevermin,maxorprecisionchange. Because this happened after clamping, the rounding could push the value outside[min, max]:ui.number(value=0.5, min=0.4, format='%.0f')became0.0without_of_limits == True.Implementation
nicegui/elements/number.py:sanitize()assignsself.value = valueinstead of re-parsingself.format % value, so it only clamps to[min, max]and appliesprecision, leavingformatstrictly for display. Theformatdocstring now says that the value itself is not rounded.examples/sqlite_database/main.py,examples/reaktiv/main.py: the age and price inputs relied onformatto round the stored value; they get a matchingprecisionso they keep storing what they show.tests/test_number.py:test_apply_format_on_blurshows the unrounded value in a bound label next to the formatted input, andtest_format_does_not_round_the_value_below_the_minimumcovers the limit case from the issue.Migration: apps that relied on
formatto round the value (e.g. the value passed toon_changeafter a blur) now get the unrounded value and needprecisionin addition, e.g.format='%.2f', precision=2.Progress
Disclosure by the author: assisted by an AI coding assistant; all changes and tests were reviewed and verified locally.
※