From e58f79c535affa9719f1a9f2b9762e338384a22e Mon Sep 17 00:00:00 2001 From: David Smith <39445562+smithdc1@users.noreply.github.com> Date: Sat, 16 Jan 2021 16:49:02 +0000 Subject: [PATCH] Improved performance of DecimalField. strip() is unnecessary because decimal.Decimal() strips the input value. --- django/forms/fields.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/django/forms/fields.py b/django/forms/fields.py index 17c7956b53..daa65d61eb 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -343,9 +343,8 @@ class DecimalField(IntegerField): return None if self.localize: value = formats.sanitize_separators(value) - value = str(value).strip() try: - value = Decimal(value) + value = Decimal(str(value)) except DecimalException: raise ValidationError(self.error_messages['invalid'], code='invalid') return value