Skip to content

Document.save not saving the doc #1246

Description

@knoxxs

Storing an instance with only primary_key set doesn't store the document. If any other field is set apart from primary_key the document is getting stored.

This must be happening as mongoengine assuming it to be update and as the instance has no other data set, hence mongoengine is getting northing in updates and removals.

Eg:

class Sample(Document):
    key = StringField(primary_key=True)
    count = IntField()

sample = Sample()
sample.key = "123"
sample.save() # does nothing

sample.count = 0
sample.save() # saves the document

I know I can use force_insert in save to make it work. but is this the desired behaviour?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions