QuerySet.extra(where=...) crashes

XMLWordPrintableJSON

    • None
    • Python Drivers
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Example:

      ERROR: test_where (queries_.test_extra.ExtraTests.test_where)
      ----------------------------------------------------------------------
      Traceback (most recent call last):
        File "/home/tim/code/django-mongodb/tests/queries_/test_extra.py", line 9, in test_where
          self.assertCountEqual(Author.objects.extra(where=["id=%s"], params=[author.id]), author)
        File "/usr/lib/python3.12/unittest/case.py", line 1198, in assertCountEqual
          first_seq, second_seq = list(first), list(second)
                                  ^^^^^^^^^^^
        File "/home/tim/code/django/django/db/models/query.py", line 390, in __iter__
          self._fetch_all()
        File "/home/tim/code/django/django/db/models/query.py", line 2000, in _fetch_all
          self._result_cache = list(self._iterable_class(self))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/tim/code/django/django/db/models/query.py", line 95, in __iter__
          results = compiler.execute_sql(
                    ^^^^^^^^^^^^^^^^^^^^^
        File "/home/tim/code/django-mongodb/django_mongodb_backend/compiler.py", line 361, in execute_sql
          query = self.build_query(self.get_project_columns(self.columns))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/tim/code/django-mongodb/django_mongodb_backend/compiler.py", line 484, in build_query
          query.lookup_pipeline = self.get_lookup_pipeline()
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/tim/code/django-mongodb/django_mongodb_backend/compiler.py", line 787, in get_lookup_pipeline
          pushed_filters = self._get_pushable_conditions()
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/tim/code/django-mongodb/django_mongodb_backend/compiler.py", line 732, in _get_pushable_conditions
          return self._collect_pushable(self.get_where())
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/tim/code/django-mongodb/django_mongodb_backend/compiler.py", line 743, in _collect_pushable
          cls._collect_pushable(sub_expr, negated=negated)
        File "/home/tim/code/django-mongodb/django_mongodb_backend/compiler.py", line 775, in _collect_pushable
          if isinstance(expr.lhs, Col) and (
                        ^^^^^^^^
      AttributeError: 'ExtraWhere' object has no attribute 'lhs'

      It should raise NotSupportedError.

            Assignee:
            Tim Graham
            Reporter:
            Tim Graham
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: