diff --git a/docs/changelog.rst b/docs/changelog.rst index 1feec343..ff227f8d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -5,6 +5,7 @@ Changelog Changes in 0.9.X - DEV ====================== +- Fix storing value of precision attribute in DecimalField #787 - Querying by a field defined in a subclass raises InvalidQueryError #744 - Add Support For MongoDB 2.6.X's maxTimeMS #778 - abstract shouldn't be inherited in EmbeddedDocument # 789 diff --git a/mongoengine/fields.py b/mongoengine/fields.py index 870d09e5..d9aeb3f1 100644 --- a/mongoengine/fields.py +++ b/mongoengine/fields.py @@ -308,7 +308,7 @@ class DecimalField(BaseField): self.min_value = min_value self.max_value = max_value self.force_string = force_string - self.precision = decimal.Decimal(".%s" % ("0" * precision)) + self.precision = precision self.rounding = rounding super(DecimalField, self).__init__(**kwargs) @@ -322,7 +322,7 @@ class DecimalField(BaseField): value = decimal.Decimal("%s" % value) except decimal.InvalidOperation: return value - return value.quantize(self.precision, rounding=self.rounding) + return value.quantize(decimal.Decimal(".%s" % ("0" * self.precision)), rounding=self.rounding) def to_mongo(self, value, use_db_field=True): if value is None: