Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Querying by a field defined in a subclass raises InvalidQueryError #744

Closed
DavidBord opened this issue Aug 21, 2014 · 0 comments
Closed

Comments

@DavidBord
Copy link
Contributor

def test_subclass_field_query(self):
    class Villain(Document):
        specialty = StringField()
        meta = dict(allow_inheritance=True)

    class Loki(Villain):
        from_asgard = BooleanField()

    Villain(specialty="mayham").save()
    Loki(specialty="mayham", from_asgard=True).save()
    list(Villain.objects(from_asgard=True))

Traceback:

Error
Traceback (most recent call last):
  File "/mongoengine/tests/document/instance.py", line 2666, in test_subclass_field_query
    list(Villain.objects(from_asgard=True))
  File "/mongoengine/mongoengine/queryset/queryset.py", line 47, in __len__
    list(self._iter_results())
  File "/mongoengine/mongoengine/queryset/queryset.py", line 81, in _iter_results
    self._populate_cache()
  File "/mongoengine/mongoengine/queryset/queryset.py", line 93, in _populate_cache
    self._result_cache.append(self.next())
  File "/mongoengine/mongoengine/queryset/base.py", line 1329, in next
    raw_doc = self._cursor.next()
  File "/mongoengine/mongoengine/queryset/base.py", line 1381, in _cursor
    self._cursor_obj = self._collection.find(self._query,
  File "/mongoengine/mongoengine/queryset/base.py", line 1415, in _query
    self._mongo_query = self._query_obj.to_query(self._document)
  File "/mongoengine/mongoengine/queryset/visitor.py", line 93, in to_query
    query = query.accept(QueryCompilerVisitor(document))
  File "/mongoengine/mongoengine/queryset/visitor.py", line 158, in accept
    return visitor.visit_query(self)
  File "/mongoengine/mongoengine/queryset/visitor.py", line 81, in visit_query
    return transform.query(self.document, **query.query)
  File "/mongoengine/mongoengine/queryset/transform.py", line 60, in query
    raise InvalidQueryError(e)
InvalidQueryError: Cannot resolve field "from_asgard"
DavidBord added a commit to DavidBord/mongoengine that referenced this issue Sep 18, 2014
DavidBord added a commit to DavidBord/mongoengine that referenced this issue Sep 27, 2014
DavidBord added a commit to DavidBord/mongoengine that referenced this issue Sep 30, 2014
DavidBord added a commit to DavidBord/mongoengine that referenced this issue Nov 5, 2014
DavidBord added a commit that referenced this issue Nov 6, 2014
fix-#744: Querying by a field defined in a subclass raises InvalidQueryE...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant