MongoEngine / MongoEngine/mongoengine
Setting primary key messes with the null kwarg
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
Mongoengine 0.20.0, PyMongo 3.10.1, Python 3.8.2, Windows 10, MongoDB Atlas
Specifying a field as being a primary key seems to mess with the null kwarg of other fields.
import mongoengine
mongoengine.connect(
...
)
class ChannelBase(mongoengine.Document):
test = mongoengine.IntField(null=True)
meta = {
"collection":"channels",
"abstract":True
}
class Channel1(ChannelBase):
channelID = mongoengine.StringField(db_field="_id",required=True)
class Channel2(ChannelBase):
channelID = mongoengine.StringField(primary_key=True,required=True)
ch1 = Channel1()
ch1.channelID = "test1"
ch1.save()
ch2 = Channel2()
ch2.channelID = "test2"
ch2.save()
The Channel1 document saves the test field as null, while the Channel2 document does not save it.

If this is intended, I cannot see why based off of the documentation.
This may also be an issue with MongoDB Atlas, but I highly doubt it.
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
The issue names no source files or tests. Start by running the provided Channel1 and Channel2 reproduction with the stated MongoEngine and MongoDB versions, then inspect the save and field-serialization path; done means the expected handling of the null field with a primary key is established and covered by a regression test.
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
- 35/100