Skip to content
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

decrementing Decimal raises InvalidDocument exception type #1320

Closed
ghost opened this issue Jun 20, 2016 · 0 comments
Closed

decrementing Decimal raises InvalidDocument exception type #1320

ghost opened this issue Jun 20, 2016 · 0 comments

Comments

@ghost
Copy link

ghost commented Jun 20, 2016

I have models like

import mongoengine as me

class Orders(me.Document):
         order_id = me.SequenceField(primary_key=True)
         total_due_amount = me.DecimalField(required=True)
         # other  irrevelant fields 

I have views like

def update_total_due_amount(request):
      # some irrelevant pre processing
      total_amount_paid = 10    # after some preprocessing assume total_amount_paid is 10
      order_obj_update = Orders.objects(order_id=order_id).update_one(dec__total_due_amount=total_amount_paid) # this raises an exception 

The actual exception is Cannot encode object: Decimal('-10.00')
I have worked around by

Orders.objects(order_id=order_id).update_one(dec__total_due_amount=int(total_amount_paid)) # observe the int()

Is this how it should have been done ? Or am I missing something ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants