appwrite / sdk-for-python

[READ-ONLY] Official Appwrite Python SDK 🐍
https://appwrite.io
BSD 3-Clause "New" or "Revised" License
230 stars 59 forks source link

🐛 Bug Report: Python SDK - Querying with a boolean value leads to " Query type does not match expected: boolean" #46

Closed superseby2 closed 2 years ago

superseby2 commented 2 years ago

👟 Reproduction steps

Trying to perform a query like so :

users_list  = database.list_documents('profiles',                                                                          

[                                                                                                                          
   Query.equal('open', True)                                                                                               
] 

👍 Expected behavior

👎 Actual Behavior

Error "Query type does not match expected: boolean" is raised.

It looks like the Python SDK just pass the value as "True" in the rest api call

https://domain.com/v1/database/collections/profiles/documents?queries%5B0%5D=open.equal%28True%29

converting the value to lowercase will make the query works

Bellow is the part that would probably need some love

appwrite/query.py
 38     def parseValues(value):                                                                                             
 39         if type(value) == str:                                                                                          
 40             return '"{}"'.format(value)                                                                                 
 41         else:                                                                                                           
 43             return value                                                                                               

maybe something like ?

appwrite/query.py
 38     def parseValues(value):                                                                                             
 39         if type(value) == str:                                                                                          
 40             return '"{}"'.format(value)                                                                                 
 39         elif type(value) == bool:                                                                                          
 40             return '{}'.format(str(value).lower())                                                                                 
 41         else:                                                                                                           
 43             return value                                                                                               

🎲 Appwrite version

Version 0.12.x

💻 Operating system

Linux

🧱 Your Environment

No response

👀 Have you spent some time to check if this issue has been raised before?

🏢 Have you read the Code of Conduct?

lohanidamodar commented 2 years ago

@superseby2 This should be fixed in Appwrite 0.13.4, the latest version. Let us know if you still have the problem.

superseby2 commented 2 years ago

As far as I can tell, the bug is still here. Python SDK use True and apprwrite is expecting true

Here is the query as output by Python SDK

documents?queries%5B0%5D=calendar_done.equal%28True%29&limit=100 which won't work

but this will work :

documents?queries%5B0%5D=calendar_done.equal%28true%29&limit=100 Seems to me more of an sdk issue. Still need to apply my patch to make this work though.

netapy commented 2 years ago

Has this ever been fixed ? I still have the issue on version v:0.15.3.402 Is there a workaround ? Thank you.

stnguyen90 commented 2 years ago

@netapy, not yet. The workaround is to manually generate the query string. So instead of Query.equal("attr", True), do "attr.equal(true)".

superseby2 commented 2 years ago

@netapy if for some reason you cannot query using the "true" vs "True" trick. What I do is simply not use a boolean field but an int field and query using 0 or 1 ...

netapy commented 2 years ago

@superseby2 thanks for the input. I have found the workaround suggested by @stnguyen90 to work very well for my case !

eldadfux commented 2 years ago

@abnegate has just merged a fixed, this is expected to be available with the next release of the SDK later this week.

superseby2 commented 2 years ago

Happy to see this fixed :)

abnegate commented 2 years ago

This fix is now released in version 1.0.0 :grin: