Skip to content
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

Invalid query is generated: For field=BitField #69

Open
fzzylogic opened this issue Sep 10, 2020 · 7 comments
Open

Invalid query is generated: For field=BitField #69

fzzylogic opened this issue Sep 10, 2020 · 7 comments

Comments

@fzzylogic
Copy link

fzzylogic commented Sep 10, 2020

Hi all, thanks for your work on this. Noticed the below when testing version 2.8.1 with not yet supported Django 3.1.1. However, it works as expected up to version 3.0.10. Just adding this here fwiw or any that misinterpret "Django 2.2 or newer" :-).

models.py:

class Book(models.Model):
    BitField = models.BooleanField(db_column="BitField", default=0)

query:
queryset = Book.objects.filter(BitField=True)

Generated T-SQL (Django 3.1.1):

SELECT TOP 10 dbo.Book.PK, dbo.Book.BitField
FROM dbo.Book
WHERE NOT dbo.Book.BitField

-- For Django up to 3.0.10 the correct T-SQL is generated:
-- ... WHERE dbo.Book.BitField = 0

Error:
An expression of non-boolean type specified in a context where a condition is expected, near 'BitField'.

@MadPepe
Copy link

MadPepe commented Sep 10, 2020

Had the same issue. We had to downgrade to 3.0.10 version of Django and the problem disappeared.

Dependencies (Not working):

  • Django==3.1
  • django-mssql-backend==2.8.1
  • pyodbc==4.0.30

@ecogels
Copy link

ecogels commented Sep 15, 2020

That issue (and more) is solved in this pull request #64.

@Asdonomar
Copy link

Same happen to me but in the User Table for the fields: is_staff, is_active, is_superuser
Django==3.1
django-mssql-backend==2.8.1
pyodbc==4.0.30

@sekar-p
Copy link

sekar-p commented Feb 11, 2021

Issue exists in django3.1.6 also. When we can expect the fixed version in PyPI

@karlkaebnick
Copy link

Tested this morning on django3.2 - issue is still present

@sa185383
Copy link

Issue still persists with django 3.2 and django-mssql-backend 2.8.1. Has any progress been made to fix this?

@fzzylogic
Copy link
Author

Inexplicably (or perhaps explicably), there's an 🅼🆂 fork that doesn't show up in the forks, that addresses this if i'm not mistaken. It also allows setting encoding and decoding for the pyodbc connection among other things.

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

7 participants