mongoengine icon indicating copy to clipboard operation
mongoengine copied to clipboard

Upsert does not update SequenceField

Open jasper-lu opened this issue 6 years ago • 1 comments

Is this intended behavior? I ran into a bug where when I called update_one withupsert=True, a sequencefield was not created for the object on creation.

jasper-lu avatar Oct 02 '19 19:10 jasper-lu

Same here. SequenceField is left empty on update_one(upsert=True, **data) or upsert_one(). Not sure if it's intended. Example code:

class Example(Document):
    meta = {"collection": "examples", "db_alias": "default"}
    example_id = SequenceField()
    title = Stringfield()

Example.objects.upsert_one(title="lorem ipsum")

A workaround is to pass set_on_insert__example_id=Example.example_id.generate() to the upsert_one() method. But it increments the counter, even in case of an update.

fmunirdev avatar Oct 28 '22 10:10 fmunirdev