Back

Facing issue with querying the database "$createdAt"

  • 1
  • Self Hosted
  • Databases
Abhishek
17 Sep, 2024, 20:34

I'm using python appwrite function.

Error: appwrite.exception.AppwriteException: Invalid query: Attribute not found in schema: _createdAt

Code:

TypeScript
results = Databases(client).list_documents('DATABASE', 'COLLECTION', [
                Query.and_queries([
                    Query.equal('id', [user['$id']]),
                    Query.between('$createdAt', start_iso, end_iso)
                ])
            ])

For date conversion: datetime.now().isoformat()

TL;DR
Developers facing issue querying the database with the "$createdAt" attribute. The problem seems to be with nested queries not recognizing the attribute. The solution might be using ISO format strings for the timestamp and datetime.now().timestamp() for inputs. The error may occur due to incorrect documentation regarding 'and_queries' instead of just 'and'. Make sure to use the correct Python SDK version.
Kenny
17 Sep, 2024, 20:38

Is it not just and? In the docs I'm not seeing and_queries

TypeScript
Query.and([
  Query.equal('id', [user['$id']]),
  Query.between("$createdAt", start_iso, end_iso)
])
Abhishek
17 Sep, 2024, 20:41

I'm on v1.5.7 self-hosted appwrite version. Using python sdk v5.0.3

Abhishek
17 Sep, 2024, 20:43
Abhishek
17 Sep, 2024, 20:45

I just checked even in Python SDK v6.1.0; it's the same. However, the documentation has and only

Abhishek
17 Sep, 2024, 20:47

I think the documentation is incorrect. In Python, or and and are built-in keywords.

Abhishek
17 Sep, 2024, 20:54

Facing issue with querying the database "$createdAt"

Jamy
18 Sep, 2024, 08:02

https://dev.to/appwrite/introducing-createdat-and-updatedat-on-each-resource-5pa

Reading the article, as far as I understand, createdAt is stored as a timestamp. Have you tried datetime.now().timestamp() for your inputs ?

Abhishek
18 Sep, 2024, 14:53

Yes, I did this and got the following error: appwrite.exception.AppwriteException: Invalid query: Query value is invalid for attribute "$createdAt"

Then I looked at different github issues and there they mention to have iso format string

Abhishek
18 Sep, 2024, 17:30

It's the same issue with almost all the query functions. It seems like $createdAt is not accessible or not available for querying.

Can any core member confirm this?

Kenny
18 Sep, 2024, 17:51

Does moving it outside of the and result in anything else?

Kenny
18 Sep, 2024, 17:51

If you remove it entirely does your first query work?

Abhishek
18 Sep, 2024, 17:59

Yes, it works outside. Only happens on nested queries

Abhishek
18 Sep, 2024, 18:03

For my use case, this works. Based on the documentation: Each query method is logically separated via AND operations. For OR operation, pass multiple values into the query method separated by commas

Kenny
19 Sep, 2024, 13:15

I'm not sure, it sounds to me like an issue with and, you might make an issue on github for it? Or see if one already exists.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more