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

TypeError: 'Q' object is not subscriptable #634

Open
SumJest opened this issue Aug 27, 2024 · 1 comment
Open

TypeError: 'Q' object is not subscriptable #634

SumJest opened this issue Aug 27, 2024 · 1 comment

Comments

@SumJest
Copy link

SumJest commented Aug 27, 2024

Using a combined filter, in one of the expressions of which negation is used, the exception appears:

Traceback (most recent call last):
  File "C:\Users\Roman\AppData\Local\Programs\PyCharm Professional\plugins\python\helpers\pydev\pydevconsole.py", line 364, in runcode
    coro = func()
           ^^^^^^
  File "<input>", line 1, in <module>
  File "C:\Users\Roman\PycharmProjects\tugan-mono\projects\server\venv\Lib\site-packages\django\db\models\manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Roman\PycharmProjects\tugan-mono\projects\server\venv\Lib\site-packages\eav\queryset.py", line 175, in wrapper
    arg = rewrite_q_expr(self.model, arg)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Roman\PycharmProjects\tugan-mono\projects\server\venv\Lib\site-packages\eav\queryset.py", line 107, in rewrite_q_expr
    rewritable = [c for c in expr.children if is_eav_and_leaf(c, gr_name)]
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Roman\PycharmProjects\tugan-mono\projects\server\venv\Lib\site-packages\eav\queryset.py", line 107, in <listcomp>
    rewritable = [c for c in expr.children if is_eav_and_leaf(c, gr_name)]
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Roman\PycharmProjects\tugan-mono\projects\server\venv\Lib\site-packages\eav\queryset.py", line 48, in is_eav_and_leaf
    and expr.children[0][0] in ['pk__in', '{}__in'.format(gr_name)]
        ~~~~~~~~~~~~~~~~^^^
TypeError: 'Q' object is not subscriptable

Expression that called exception:

ForeignProduct.objects.filter(Q(id=86) & ~Q(marketplace_user_id=1))

The model code is quite large, because there is inheritance. But if it is needed, I will send it.
In the project, I got around this bug by using the exclude method for expressions with negation, but it isn't solution.

Steps to Reproduce

Just filter some EavQuerySet with more than 1 expression, one of which is negated.

Your Environment

Include relevant details about the environment you experienced the bug in.

  • Version used: 1.6.1
  • Environment name and version (e.g. Django 2.0.4, pip 9.0.1): Django 3.2.9
  • Operating System and version: Windows / Ubuntu
@Dresdn
Copy link
Contributor

Dresdn commented Sep 3, 2024

Have you noticed any other queries that fail? Take a look at test_queries.py for all the use cases we're testing, with this one missing.

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

2 participants