MongoEngine / MongoEngine/mongoengine
Bug: LazyReferenceField passthrough on classes with methods do not work
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
I have a LazyReferenceField to a document class that I want to call methods on, but that does not work, because the __getattr__ method of a LazyReference is implemented via the subscript operator instead of a getattr call.
Relevant line: https://github.com/MongoEngine/mongoengine/blob/master/mongoengine/base/datastructures.py#L468
Replacing return document[name] with return getattr(document, name) would solve the problem.
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
Read mongoengine/base/datastructures.py around line 468, focusing on LazyReference.getattr and how the referenced document is accessed. Verify the behavior with a document class that defines a method, then add regression coverage and run the relevant test suite; done means method access through LazyReferenceField works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100