MongoEngine / MongoEngine/mongoengine

Empty values handling in BooleanField

Open
#1,396 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
4.3k
Forks
1.2k
Avg merge
4h 41m
Merged PRs (30d)
11

Description

Currently to_mongo calls to_python regardless of the value being empty. This is different to the django behaviour.

The problem, that this causes, is that, for example, BooleanField saves false to the database, instead of null or StringField saves empty string. Django does check value being empty for the first and the second case.

To my opinion this is really misleading when I save document with an explicitly unset BooleanField and it saves with false value.

I'll be happy to provide a PR with these changes, if it wasnt done on purpose.

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 the BooleanField and StringField implementations and reading their to_mongo and to_python methods. Compare their empty-value handling with the Django field behavior linked in the issue, then add or update coverage so unset BooleanField values remain null and empty StringField values remain empty; done means these values are not coerced during persistence.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.