MongoEngine / MongoEngine/mongoengine
upsert_one doesn't use defined id/primary_key type.
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
Details
When we use upsert_one the defined id type field is ignored and MongoEngine generate a ObjectId.
How to reproduce:
from mongoengine import *
class D2(DynamicDocument):
custom_id = UUIDField(required=True, primary_key=True, default=uuid4)
label = StringField()
value = IntField()
connect()
D2.objects(label='A').upsert_one(value=1)
print(type(D2.objects().get().id))
Current result:
<class 'bson.objectid.ObjectId'> is displayed
Expected result:
<class 'uuid.UUID'>
Version
mongoengine: '0.16.3'
pymongo: '3.7.2'
Python 2.7.15
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the upsert_one entry point and reproduce the example using a primary-key UUIDField on DynamicDocument. Trace how the upsert creates an ID and compare it with normal document creation. Done means the reproduced document has a uuid.UUID ID rather than a MongoDB ObjectId.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100