MongoEngine / MongoEngine/mongoengine
LazyReferenceField requires check for None before using fetch() or pk
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
Hello, I'm relatively new to MongoEngine so I apologize in advance if this is a bad idea for some reason. That said, it seems like using LazyReferenceField would be much nicer if one didn't have to to check whether the field has a value before calling fetch() or accessing pk. Why not just have build_lazyref() allow for None to be passed on as the value of the LazyReference, and then have LazyReference.fetch() return None if self.id = None?
I'm willing to try setting up a dev environment and creating a PR for this if people think it's a good suggestion. Thanks for reading!
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 by locating build_lazyref() and LazyReference.fetch(), then trace how LazyReference exposes pk when the referenced value is absent. The requested behavior is to allow None and have fetch() and pk access return None; confirm the existing LazyReference behavior before determining the needed coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100