๐ Bug Report: Can't filter by DateTime
mahyess opened this issue ยท 0 comments
mahyess commented
๐ Reproduction steps
To get the list of documents, filtered by datetime an intuitive method would be something like this:
# get datetime before an hour
hour_ago = datetime.now()-timedelta(hours=1)
databases = Databases(client)
doclist = await databases.list_documents(
"databaseID", # database_id
"collectionID", # collection_id
[
# queries
Query.greaterThan("$updatedAt", hour_ago),
]);
But this results in an empty list. The issue I found was its because of how the value of datetime is parsed. The datetime is simply set str(datetime)
to query, but the resulting string is invalid for filtering the documents.
Workaround
The way I solved this is by using the query string by myself.
# get datetime before an hour
hour_ago = datetime.utcnow()-timedelta(hours=1). # requires utc datetime
databases = Databases(client)
doclist = await databases.list_documents(
"databaseID",
"collectionID",
[
f'greaterThan("$updatedAt", ["{hour_ago.isoformat()}"])',
]);
๐ Expected behavior
It should result in a list with appropriately filtered documents, but it doesn't.
๐ Actual Behavior
It either results in all of the documents or none at all depending on the filter greaterThan
or lessThan
used.
๐ฒ Appwrite version
Version 0.10.x
๐ป Operating system
Linux
๐งฑ Your Environment
No response
๐ Have you spent some time to check if this issue has been raised before?
- I checked and didn't find similar issue
๐ข Have you read the Code of Conduct?
- I have read the Code of Conduct