mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 19:46:46 +00:00
Catch invalid decimal conversion (#8470)
- Thanks to fuzzers reported by sentry.io
This commit is contained in:
parent
9ab532a067
commit
1eae56ff1e
@ -4,6 +4,7 @@ import sys
|
|||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
@ -152,7 +153,10 @@ class DatePickerFormField(forms.DateField):
|
|||||||
def round_decimal(value, places, normalize=False):
|
def round_decimal(value, places, normalize=False):
|
||||||
"""Round value to the specified number of places."""
|
"""Round value to the specified number of places."""
|
||||||
if type(value) in [Decimal, float]:
|
if type(value) in [Decimal, float]:
|
||||||
|
try:
|
||||||
value = round(value, places)
|
value = round(value, places)
|
||||||
|
except Exception:
|
||||||
|
raise ValidationError(_('Invalid decimal value') + f' ({value})')
|
||||||
|
|
||||||
if normalize:
|
if normalize:
|
||||||
# Remove any trailing zeroes
|
# Remove any trailing zeroes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user