djangopyodbcdjango-mssql-backend

Object.Filter() error using boolean fields


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?


Solution

  • 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.