MongoEngine / MongoEngine/mongoengine
Pylint warning - Class 'User' has no 'objects' member (no-member)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
PyLint is complaining:
Class 'User' has no 'objects' member (no-member)
Class 'User' has no 'DoesNotExist' member (no-member)
This is because objects is assigned in the metaclass base/metaclasses.py:345:
# Provide a default queryset unless exists or one has been set
if 'objects' not in dir(new_class):
new_class.objects = QuerySetManager()
I think having it defined in the base document would have the effect but be more discoverable:
class Document(BaseDocument):
objects = QuerySetManager()
Similarly you could do
from mongoengine.queryset import DoesNotExist, MultipleObjectsReturned
class Document(BaseDocument):
DoesNotExist = DoesNotExist
MultipleObjectsReturned = MultipleObjectsReturned
Also the per-class exceptions can have their names to include model name:
# Merge in exceptions with parent hierarchy
exceptions_to_merge = (DoesNotExist, MultipleObjectsReturned)
module = attrs.get('__module__')
for exc in exceptions_to_merge:
_name = exc.__name__
parents = tuple(getattr(base, _name) for base in flattened_bases
if hasattr(base, _name)) or (exc,)
# Create new exception and set to new_class
exception = type(name + _name, parents, {'__module__': module})
setattr(new_class, _name, exception)
Thus Sentry having such an exceptions + __repr__ would give hint what model the exception belongs to.
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 base/metaclasses.py:345 and inspect the Document/BaseDocument definitions to understand how objects and per-class exceptions are exposed. Compare the proposed base-class members and model-specific exception names against the Pylint warnings. Done means User.objects and User.DoesNotExist are discoverable without no-member warnings, with the requested exception behavior preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100