Skip to content
Back

Python TablesDB Rework

  • 1
  • 3
  • Functions
  • Cloud
Chefe#8332
18 Mar, 2026, 14:30

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)

TypeScript
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?

TL;DR
The user experienced issues with TablesDB while using the newest Appwrite SDK version 16.0.0. Reverting back to version 15.3.0 resolved the problem. A proposed solution involving error handling for request body parsing was provided and implemented. Updating back to the newest version of Appwrite SDK should now work fine.
Chefe#8332
18 Mar, 2026, 14:30

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"

TypeScript
                ])
        ]
    )
18 Mar, 2026, 15:12

Try doing it something like this:

TypeScript
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(["*"])   
    ]
)
18 Mar, 2026, 15:12

See if that works

18 Mar, 2026, 15:15

Let me check 🙂 thanks for your fast reply

18 Mar, 2026, 15:18

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

18 Mar, 2026, 15:35

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'}

18 Mar, 2026, 15:42

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?

20 Mar, 2026, 08:26

No Update?

25 Mar, 2026, 14:30

1 Week and no update, great

25 Mar, 2026, 15:15

Hey! Really sorry for the delay

25 Mar, 2026, 15:15

Can you try this:

25 Mar, 2026, 15:15
TypeScript
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
})
27 Mar, 2026, 10:23

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)

27 Mar, 2026, 14:17

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:

TypeScript
import json

try:
    body = json.loads(context.req.body_text) if context.req.body_text else {}
except Exception:
    body = {}
27 Mar, 2026, 17:05

Okay i will test this tomorrow and will let you know, thanks for your time 🙂

31 Mar, 2026, 14:40

<@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

31 Mar, 2026, 16:24

It’s because of new Appwrite TablesDB updates and the error you were getting here was because of improper error handling.

31 Mar, 2026, 16:36

Ah so you think if i update the requirements to the newest version again it should work?

31 Mar, 2026, 16:50

Yes, it should work now as it was mainly the request body parsing issue.

31 Mar, 2026, 16:53

Ah okay i will try thanks for your help ❤️

1 Apr, 2026, 04:18

Mention not 😊

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