Skip to content

Filtering with MyModel.objects.filter(content='...') does not match any models #3

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

Open
dcki opened this issue Dec 13, 2023 · 2 comments

Comments

@dcki
Copy link

dcki commented Dec 13, 2023

Example:

Given a model with a compressed field named content:

>>> m = MyModel.objects.last()
>>> m.id
123
>>> m.content
'abc'
>>> len(list(MyModel.objects.filter(content=m.content)))
0

That should be at least 1, not 0.

These still work though, as documented:

>>> len(list(MyModel.objects.filter(content__in=[m.content])))
1
>>> len(list(MyModel.objects.filter(content__startswith=m.content)))
1
@davidfstr
Copy link
Contributor

MyModel.objects.filter(content=m.content)

I suspect you may need to rewrite this query as one of:

  • MyModel.objects.filter(content__exact=m.content)
  • MyModel.objects.filter(content__iexact=m.content)
  • MyModel.objects.filter(content=Compress(m.content))

Even assuming the above is true, I agree that it's confusing for the original query to not work. I'll plan to update the documentation.

@davidfstr
Copy link
Contributor

  • MyModel.objects.filter(content__exact=m.content)
  • MyModel.objects.filter(content__iexact=m.content)

Actually these won't work because apparently neither the exact nor the iexact filters are currently overridden by the implementation.

That should be fixed too, since __exact and __iexact are useful.

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