-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dict field can't handle python's Decimal #707
Comments
Python Decimal should be saved via MongoEngine DecimalField. By the way DecimalField it self looks unusable see #637. |
It's not a duplicate. |
@thedrow First of all it is very hard to understand In favor of 0.9 I would say that we should plan for next release:
As for now I think we should record this as known issue as it is very specific case that could be easily worked around. |
It can't be easily worked around because |
Well you are always able to check deep into dict values before saving and It could be done using custom On Wed, Nov 26, 2014 at 2:39 PM, Ivan Kleshnin [email protected]
Serge Matveenko |
A test that reproduces it:
|
@thedrow, are you sure we want to solve this? indeed, bson shouldn't serialize Decimal objects so why should we coerce it? |
Lets say we'll represent stuff like |
Starting with MongoDB v3.4, you can use the Decimal BSON Type. |
For anyone looking for a quick answer: from bson.decimal128 import Decimal128
for key in ['decimal_key1', 'decimal_key2']:
row[key] = Decimal128(row[key]) You need to convert the https://api.mongodb.com/python/current/api/bson/decimal128.html#module-bson.decimal128 You also require MongoDB 3.4+. |
Attempt to save
decimal.Decimal
object as one of the values inDictField
raisesbson.errors.InvalidDocument: Cannot encode object: Decimal('20000')
The text was updated successfully, but these errors were encountered: