From 7ce8768c1937f7522e650fa42677fe4b1725c7e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B8=CC=86=20=D0=AF?= =?UTF-8?q?=D0=BD=D1=86=D0=B5=D0=BD?= Date: Tue, 6 Dec 2016 10:42:10 +0500 Subject: [PATCH] Added rounding for unicode return value of to_mongo in DecimalField. Closes #1103 --- AUTHORS | 1 + docs/changelog.rst | 1 + mongoengine/fields.py | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 12475c2e..1d724718 100644 --- a/AUTHORS +++ b/AUTHORS @@ -242,3 +242,4 @@ that much better: * xiaost7 (https://github.com/xiaost7) * Victor Varvaryuk * Stanislav Kaledin (https://github.com/sallyruthstruik) + * Dmitry Yantsen (https://github.com/mrTable) diff --git a/docs/changelog.rst b/docs/changelog.rst index ad710bb1..61ea45c4 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -7,6 +7,7 @@ Changes in 0.10.8 - Added ability to specify an authentication mechanism (e.g. X.509) #1333 - Added support for falsey primary keys (e.g. doc.pk = 0) #1354 - Fixed BaseQuerySet#sum/average for fields w/ explicit db_field #1417 +- Fixed absent rounding for DecimalField when `force_string` is set. #1103 Changes in 0.10.7 ================= diff --git a/mongoengine/fields.py b/mongoengine/fields.py index 783aac46..2ad921d5 100644 --- a/mongoengine/fields.py +++ b/mongoengine/fields.py @@ -341,7 +341,7 @@ class DecimalField(BaseField): if value is None: return value if self.force_string: - return unicode(value) + return unicode(self.to_python(value)) return float(self.to_python(value)) def validate(self, value):