Hi, i starting to rework some older functions to TablesDB list_rows Method. I used list_documents with a resultset with worked fine. Now i tried to get all rows from a specific table and have the data in it. So i started with the Documentation and changed my function to the following.
from appwrite.client import Client from pydantic import BaseModel from datetime import datetime from typing import Optional from appwrite.services.tables_db import TablesDB from appwrite.query import Query import os
class Product(BaseModel): image: str description_de: str description_en: str description_fr: str price: float url: str visible: bool uvp: float name_en: str name_fr: str name_de: str popularity: int
def main(context): client = ( Client() .set_endpoint(os.environ["APPWRITE_FUNCTION_API_ENDPOINT"]) .set_project(os.environ["APPWRITE_FUNCTION_PROJECT_ID"]) .set_key(context.req.headers["x-appwrite-key"]) ) databases = TablesDB(client)
database_id = "67615fe8003a2b1eaebf"
products_id = "677ae7d9003770708d10"
body = context.req.body_json or {}
offset = int(body.get("offset", 0))
context.log(f"Offset from body: {offset}")
limit = 25
try:
response = databases.list_rows(
database_id=database_id,
table_id=products_id,
#model_type=Product,
queries=[
Query.equal("visible", True),
Query.order_desc("$createdAt"),
Query.limit(limit),
Query.offset(offset)
]
)
context.log(response)
data = response.model_dump()
return context.res.json(data)
except Exception as e:
return context.res.json({"error": str(e)}, 500)
Response But as you can see no real Data are in it. Even if i add them via Query.select Anyone can help me here?
Query with Select response = databases.list_rows( database_id=database_id, table_id=products_id, model_type=Product, queries=[ Query.equal("visible", True), Query.order_desc("$createdAt"), Query.limit(limit), Query.offset(offset), Query.select([ "$id", "name_en", "name_fr", "name_de", "price", "url", "visible", "uvp", "popularity", "image", "description_de", "description_en", "description_fr"
])
]
)
Try doing it something like this:
response = databases.list_rows(
database_id=database_id,
table_id=products_id,
model_type=Product,
queries=[
Query.equal("visible", True),
Query.order_desc("$createdAt"),
Query.limit(limit),
Query.offset(offset),
Query.select(["*"])
]
)
See if that works
Let me check 🙂 thanks for your fast reply
That is the response in my Client ( First Log) And thats in my Response on Appwrite under Functions Executions Logs ( Second Log) It seems that no options takes effect. I use the newest appwrite sdk, requirements.txt -> appwrite without any version
Additionally tables_db = TablesDB(client)
Fetch multiple rows with type safety
result = tables_db.list_rows( database_id="67615fe8003a2b1eaebf", table_id="677ae7d9003770708d10", )
for row in result.rows: print(f"{row.data}")
If i use that directly in a Python Script Its working, anyone has ideas?
Resultset example: 'popularity': 0, 'productImages': '69a81cf70020f99816ec', 'productManufacturer': '69a2b7a60badb3188f32'}
I reverted back to 15.3.0 and i am getting responses again {"total":28,"rows":[{"image":"linkremoved,"description_de"
Any ideas what i forget to add for 16.0.0?
No Update?
1 Week and no update, great
Hey! Really sorry for the delay
Can you try this:
response = databases.list_rows(
database_id=database_id,
table_id=products_id,
queries=[
Query.equal("visible", True),
Query.order_desc("$createdAt"),
Query.limit(limit),
Query.offset(offset),
Query.select(["*"])
]
)
rows = [
{
"id": row.id,
"createdAt": row.createdat,
"updatedAt": row.updatedat,
**(row.data or {})
}
for row in response.rows
]
return context.res.json({
"total": response.total,
"rows": rows
})
Hi <@1329045306997866509> i reverted the old function to the deprecated functions until we find a solution. i created a new function and added your part. On the Execution Log of that Function
Click to copy
Traceback (most recent call last): File "/usr/local/server/src/server.py", line 148, in action output = await asyncio.wait_for( ^^^^^^^^^^^^^^^^^^^^^^^ execute(context), timeout=safeTimeout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/usr/local/lib/python3.14/asyncio/tasks.py", line 488, in wait_for return await fut ^^^^^^^^^ File "/usr/local/server/src/server.py", line 143, in execute return userModule.main(context) ~~~~~~~~~~~~~~~^^^^^^^^^ File "/usr/local/server/src/function/src/main.py", line 27, in main body = context.req.body_json or {} ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/server/src/function_types.py", line 53, in body_json return json.loads(self.body_text) ~~~~~~~~~~^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.14/json/init.py", line 352, in loads return _default_decoder.decode(s) ~~~~~~~~~~~~~~~~~~~~~~~^^^ File "/usr/local/lib/python3.14/json/decoder.py", line 345, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.14/json/decoder.py", line 363, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
No worries, I've also experienced these types of errors. You can replace body = context.req.body_json or {} with the following type safe version with proper error handling:
import json
try:
body = json.loads(context.req.body_text) if context.req.body_text else {}
except Exception:
body = {}
Okay i will test this tomorrow and will let you know, thanks for your time 🙂
<@1329045306997866509>
sorry for the delay but this seems to work
total 38.0JS:38
rows
0
id "69bed26268d38ca0cbec"
createdAt "2026-03-21T17:16:18.432+00:00"
updatedAt "2026-03-21T17:22:29.883+00:00"
image "https://fra.cloud.appwrite.io/v1/storage/
so why this is working and the other function not? i will retest this with the old function
It’s because of new Appwrite TablesDB updates and the error you were getting here was because of improper error handling.
Ah so you think if i update the requirements to the newest version again it should work?
Yes, it should work now as it was mainly the request body parsing issue.
Ah okay i will try thanks for your help ❤️
Mention not 😊
Recommended threads
- Issue Related to Presence
```PresenceService: upsert error – AppwriteException: user_unauthorized, The current user is not authorized to perform the requested action. (401) ...
- Can't create or update functions via CLI...
Self-hosted 1.9.5 — all function create/update return 500: Unknown attribute: "providerBranches" (metadata ↔ physical-column desync after upgrade) Env: Appwrit...
- Refund
i started with the free version and then switch to pro and pay the fee. Before ending of the month, i switch back to free plan. got the confirmation email t...