Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

ModelMultipleChoiceFilter with lookup_expr='in' #1106

Closed
emilt27 opened this issue Jul 17, 2019 · 1 comment
Closed

ModelMultipleChoiceFilter with lookup_expr='in' #1106

emilt27 opened this issue Jul 17, 2019 · 1 comment

Comments

@emilt27
Copy link

emilt27 commented Jul 17, 2019

We had the following field definition:

category = django_filters.ModelMultipleChoiceFilter(
    queryset=Category.objects.all(), 
    lookup_expr='in',
)

it worked correctly until last django-filter release. Now it's broken. Removing lookup_expr solves the issue, but It would be great to have more detailed message.

@rpkilby
Copy link
Collaborator

rpkilby commented Jul 17, 2019

#1054 changed this. I don't think lookup_expr was previously used, and by default, Q objects are OR'ed together, so the result looks like it was performing an in lookup. e.g.,

MyModel.objects.filter(Q(field='value1') | Q(field='value2'))

The PR changed this so lookup expressions are accounted for, so you could queries like

MyModel.objects.filter(Q(field__contains='value1') | Q(field__contains='value2'))

However, in your case, the in lookup expects a list of values, which is why you get an error. It should be safe to drop lookup_expr='in'

Repository owner locked and limited conversation to collaborators Aug 26, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants