MongoEngine / MongoEngine/mongoengine
Setter does not behave as it should.
Open
Nobody has claimed this yet.
Bug
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
import mongoengine as me
class Product(me.Document):
price = me.DecimalField(force_string=True, precision=2)
p = Product(price=10.50)
p.to_mongo()
# >> SON([('price', '10.50')])
p = Product()
p.price = 10.50
p.to_mongo()
# >> SON([('price', '10.5')])
Am I doing something wrong?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating DecimalField and compare the conversion path used during Product initialization with the path used when assigning p.price afterward. Reproduce the two examples and trace how force_string and precision are applied. Done means both assignment styles serialize price consistently, with the expected two decimal places.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100