1

When I try to use model.objects.filter(mybooleanfield=True) gives me this error

('42000', "[42000] [Microsoft] [SQL Server Native Client 11.0] [SQL Server] A non-Boolean expression was specified in a context where a condition was expected, near 'mybooleanfield'. (4145) (SQLExecDirectW) ")

But this only happens when use the filter with some BooleanField if I use PositiveIntegerField, CharField, DateTimeField or TextField there's no problem with the filter. I think this could be for the verions I use

Python 3.9.0
Django 3.1.3
Pyodbc 4.0.30
Django-mssql-backend 2.8.1

I need to use as condition my BooleanField. Someone knows why this happend?

M. Gar
  • 889
  • 4
  • 16
  • 33
  • Can you share an example of the line that is causing the issue ? Or a sample of your code. Give also the line where you define your BooleanField. – lbris Dec 07 '20 at 23:03

1 Answers1

6

This is caused by Django 3.1.x. More info here: https://github.com/ESSolutions/django-mssql-backend/issues/69.

You can either downgrade django to 3.0.x or (which I recommend) use the latest master of https://github.com/ESSolutions/django-mssql-backend in which a patch has solved this issue for Django 3.1.x. There has been no release since this patch.

Glenn D.J.
  • 1,874
  • 1
  • 8
  • 19