Skip to content

StringField (and potentially others) removing fields from mongo if set to default, if previously set. #2462

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

Open
Gentatsu opened this issue Jan 8, 2021 · 1 comment

Comments

@Gentatsu
Copy link

Gentatsu commented Jan 8, 2021

I've a simple document with a StringField with a default of an empty string (""). When I retrieve a document, and save, it does not record it as a field in the db. This is the expected behaviour.

Annoyingly, though, there's a weird behaviour that I've observed. If I set the field to something other than the default, and save, it will record it in the db. Then if I set it to an empty string "" again, the field is deleted from the db. This wouldn't be a big deal, but when I use a QuerySet to do Whatever.objects(field=""), it returns nothing as QuerySets do not work on non-present fields in the db even if they are defaulted. They're separate issues, so I'm focusing on the first.

Mongoengine version is: 0.22.1
mongo version: 4.0.8

@bagerard
Copy link
Collaborator

I agree that this behavior is misleading, it's an historical one unfortunately so it's not straightforward to change but I'll probably look into this after merging #2517 which is also a step in that direction

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

No branches or pull requests

2 participants