Skip to content

DecimalField precision is ignored in wtforms, defaults to 2 #341

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
PeterKharchenko opened this issue Oct 11, 2018 · 0 comments · Fixed by #343
Closed

DecimalField precision is ignored in wtforms, defaults to 2 #341

PeterKharchenko opened this issue Oct 11, 2018 · 0 comments · Fixed by #343
Labels
type: bug Something isn't working

Comments

@PeterKharchenko
Copy link
Contributor

PeterKharchenko commented Oct 11, 2018

Wtform's DecimalField "places" attribute defaults to 2, disregarding mongoengine's DecimalField "precision" attribute.
One of the negative scenarios - if the document is edited by user using wtform (say, some other field is edited), decimal value is rounded to 2 places and data is lost.

Solved it by replacing

return f.DecimalField(**kwargs)

with

return f.DecimalField(places=getattr(field, 'precision', None),**kwargs)

in wtf/orm.py, line 148

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type: bug Something isn't working
Projects
None yet
2 participants