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 1/4] 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): From 3b71a6b5c521e204c7c18d6ddd9eea6070d71b25 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 11:33:44 +0500 Subject: [PATCH 2/4] Improved tests to avoid regression Issue #1103 --- tests/fields/fields.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/tests/fields/fields.py b/tests/fields/fields.py index 2153a42e..cd20d362 100644 --- a/tests/fields/fields.py +++ b/tests/fields/fields.py @@ -483,27 +483,41 @@ class FieldTest(unittest.TestCase): def test_decimal_storage(self): class Person(Document): - btc = DecimalField(precision=4) + float_value = DecimalField(precision=4) + string_value = DecimalField(precision=4, force_string=True) Person.drop_collection() - Person(btc=10).save() - Person(btc=10.1).save() - Person(btc=10.11).save() - Person(btc="10.111").save() - Person(btc=Decimal("10.1111")).save() - Person(btc=Decimal("10.11111")).save() + values_to_store = [10, 10.1, 10.11, "10.111", Decimal("10.1111"), Decimal("10.11111")] + for store_at_creation in [True, False]: + for value in values_to_store: + # to_python is called explicitly if values were sent in the kwargs of __init__ + if store_at_creation: + Person(float_value=value, string_value=value).save() + else: + person = Person.objects.create() + person.float_value = value + person.string_value = value + person.save() # How its stored - expected = [{'btc': 10.0}, {'btc': 10.1}, {'btc': 10.11}, - {'btc': 10.111}, {'btc': 10.1111}, {'btc': 10.1111}] + expected = [ + {'float_value': 10.0, 'string_value': '10.0000'}, + {'float_value': 10.1, 'string_value': '10.1000'}, + {'float_value': 10.11, 'string_value': '10.1100'}, + {'float_value': 10.111, 'string_value': '10.1110'}, + {'float_value': 10.1111, 'string_value': '10.1111'}, + {'float_value': 10.1111, 'string_value': '10.1111'}] + expected.extend(expected) actual = list(Person.objects.exclude('id').as_pymongo()) self.assertEqual(expected, actual) # How it comes out locally expected = [Decimal('10.0000'), Decimal('10.1000'), Decimal('10.1100'), Decimal('10.1110'), Decimal('10.1111'), Decimal('10.1111')] - actual = list(Person.objects().scalar('btc')) - self.assertEqual(expected, actual) + expected.extend(expected) + for field_name in ['float_value', 'string_value']: + actual = list(Person.objects().scalar(field_name)) + self.assertEqual(expected, actual) def test_boolean_validation(self): """Ensure that invalid values cannot be assigned to boolean fields. From c6c5f85abbb65461a0a4c51f4eb518dc0d6fcfa3 Mon Sep 17 00:00:00 2001 From: Stefan Wojcik Date: Sat, 10 Dec 2016 23:30:16 -0500 Subject: [PATCH 3/4] update the changelog with everything we've added in v0.10.8 --- docs/changelog.rst | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index ad710bb1..fc70f6b1 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,9 +4,19 @@ Changelog Changes in 0.10.8 ================= +- Added support for QuerySet.batch_size (#1426) +- Fixed query set iteration within iteration #1427 +- Fixed an issue where specifying a MongoDB URI host would override more information than it should #1421 +- Added ability to filter the generic reference field by ObjectId and DBRef #1425 +- Fixed delete cascade for models with a custom primary key field #1247 - 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 QuerySet#sum/average for fields w/ explicit db_field #1417 +- Fixed filtering by embedded_doc=None #1422 +- Added support for cursor.comment #1420 +- Fixed doc.get__display #1419 +- Fixed __repr__ method of the StrictDict #1424 +- Added a deprecation warning for Python 2.6 Changes in 0.10.7 ================= From 6f5f5b47115a776b7147c0dc6ad0cb8e79a4bf16 Mon Sep 17 00:00:00 2001 From: Stefan Wojcik Date: Sat, 10 Dec 2016 23:36:06 -0500 Subject: [PATCH 4/4] version bump (forgot to do it with v0.10.8 release, so have to go for v0.10.9) --- mongoengine/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoengine/__init__.py b/mongoengine/__init__.py index d2e26ebf..1544aa51 100644 --- a/mongoengine/__init__.py +++ b/mongoengine/__init__.py @@ -14,7 +14,7 @@ from signals import * __all__ = (list(document.__all__) + fields.__all__ + connection.__all__ + list(queryset.__all__) + signals.__all__ + list(errors.__all__)) -VERSION = (0, 10, 7) +VERSION = (0, 10, 9) def get_version():