0

I'm currently upgrading a Django project from 2.2 to 3.2, but I'm getting an error from SQL Server when trying to load a View:

ProgrammingError at /my/django/url ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]An expression of non-boolean type specified in a context where a condition is expected, near ')'. (4145) (SQLExecDirectW)")

I have a queryset that is filtering on a Boolean Field ('islead'), the queryset contains .filter(islead=True), however when I load the View, I can see from Django debug toolbar that the SQL query doesn't include "WHERE islead = TRUE", it only has "WHERE islead" with no condition.

This works fine in Django 2.2. Here is an extract of my code:

models.py:
class LecturerCourseYear(models.Model):
    ay = models.IntegerField(db_column='AY', primary_key=True) 
    code = models.CharField(db_column='Code', max_length=12) 
    lecturer = models.ForeignKey('Lecturers', models.DO_NOTHING, db_column='lecturer', max_length=12)
    islead = models.BooleanField(db_column='IsLead')

views.py:
def edit_course(request, code, ay):
    primary_lecturer_response = LecturerCourseYear.objects.filter(ay=ay, code=code, islead=True).order_by('position')
    initialData = {'primary_lecturer': ','.join([lecturer.lecturer.id for lecturer in primary_lecturer_response]),  
    form = editCourseForm(initial=initialData) 
    return render(request, 'courses/edit-course.html', {'form': form})
stewic
  • 1
  • 1

1 Answers1

0

Fixed by downloading latest django-mssql-backend code

stewic
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 21 '22 at 17:26