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

Unable to parse Boolean SQL condition #562

Open
magmonium opened this issue Jul 4, 2021 · 7 comments
Open

Unable to parse Boolean SQL condition #562

magmonium opened this issue Jul 4, 2021 · 7 comments

Comments

@magmonium
Copy link

description

Djongo unable to parse following where condition for Boolean value.

'SELECT "company_config"."_id", "company_config"."company", "company_config"."user", "company_config"."visitedAt", "company_config"."isWatching" FROM "company_config" WHERE ("company_config"."isWatching"

Python script


from djongo import models

  class Config(models.Model):

    class Meta:
        unique_together = (('company', 'user'))

    _id = models.ObjectIdField()
    company =  models.CharField(max_length=20)
    user = models.CharField(max_length=20, default='dibyendu')
    visitedAt = models.DateField(default=None)
    isWatching = models.BooleanField(default=False)

  Config.objects.filter(isWatching=True, user="dibyendu")

Traceback


raise SQLDecodeError
djongo.exceptions.SQLDecodeError:

        Keyword: None
        Sub SQL: None
        FAILED SQL: ('SELECT "company_config"."_id", "company_config"."company", "company_config"."user", "company_config"."visitedAt", "company_config"."isWatching" FROM "company_config" WHERE ("company_config"."isWatching" AND "company_config"."user" = %(0)s)',)
        Params: (('dibyendu',),)
        Version: 1.3.6
@ngocngoan
Copy link

ngocngoan commented Jul 9, 2021

@magmonium I also have the same problem.

The solution:

Config.objects.filter(isWatching__in=[True], user="dibyendu")

But it is just a temporary solution because many libraries use filter syntax like yours

@magmonium
Copy link
Author

@ngocngoan thanks for your reply with workaround. I am going to use this solution till this request is addressed. :)

@fduraibi
Copy link

fduraibi commented Aug 1, 2021

Seems like the issue has been raised from a year ago and still not fixed!
#465

@frostming
Copy link
Contributor

frostming commented Aug 4, 2021

Here is a monkey patch approach that is less interruptive:

from djongo.base import DatabaseWrapper
from djongo.operations import DatabaseOperations

class PatchedDatabaseOperations(DatabaseOperations):

    def conditional_expression_supported_in_where_clause(self, expression):
        return False


DatabaseWrapper.ops_class = PatchedDatabaseOperations

import this file in either manage.py or settings.py and the issue will be solved.

Someone can submit a PR based on the above solution.

@redigaffi
Copy link

Why is this issue closed? I'm still having this issue.

@Dkr0l
Copy link

Dkr0l commented Sep 28, 2021

Issue still present, had to use "__in=[True]" workaround.
Could we get this reopened?

@ajwad-shaikh
Copy link

It is 2022 - still facing this issue. In the past three hours, I have explored the corners of dark webs and contemplated quitting my career.

That said, thank you @ngocngoan

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