MongoEngine / MongoEngine/mongoengine

Setter does not behave as it should.

Open
#1,059 3 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.