Opened 2 hours ago
Last modified 2 hours ago
#37579 assigned Bug
numberformat.format() raises InvalidOperation for Decimal("NaN") with decimal_pos
| Reported by: | Shakil Ur Rehman | Owned by: | Shakil Ur Rehman |
|---|---|---|---|
| Component: | Utilities | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Shakil Ur Rehman | Triage Stage: | Unreviewed |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
django.utils.numberformat.format() checks if not number.is_finite(): *after* comparing abs(number) < cutoff when decimal_pos is provided. Comparing Decimal("NaN") against cutoff raises decimal.InvalidOperation.
Minimal reproduction:
from decimal import Decimal
from django.conf import settings
from django.utils.numberformat import format as nformat
settings.configure(USE_I18N=False, USE_THOUSAND_SEPARATOR=False)
nformat(Decimal("NaN"), ".", decimal_pos=2)
Traceback:
File "django/utils/numberformat.py", line 48, in format
if abs(number) < cutoff:
decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]
Expected behavior:
if not number.is_finite(): should be checked before the decimal_pos cutoff comparison so Decimal("NaN") returns "NaN" (matching decimal_pos=None).
Change History (3)
comment:1 by , 2 hours ago
| Cc: | added |
|---|
comment:2 by , 2 hours ago
| Has patch: | set |
|---|
comment:3 by , 2 hours ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
Note:
See TracTickets
for help on using tickets.