Back

[SOLVED] debug the Python Function

  • 0
  • Functions
bluesky
10 Sep, 2023, 07:33

I need help about function, always failed when execute

How can I debug the function?

TL;DR
The user had a problem with debugging a Python function in Appwrite. They were trying to create an object like the Appwrite function send, but were encountering issues. Another user informed them that it is possible to run the function locally, but with some limitations and gotchas. They also provided an example function using the pre-1.4x syntax. The user then asked how they can debug their code locally before deploying it. Another user realized that the example syntax was for 1.4x, which the Cloud version is not on yet. The user clarified that they are using the cloud version. The thread ends with the user sharing
bluesky
10 Sep, 2023, 07:33

This my code

darShan
10 Sep, 2023, 08:03

I'm not sure if your path in the appwrite.json is correct.

bluesky
10 Sep, 2023, 08:09

My appwrite.json place on root of dir

darShan
10 Sep, 2023, 08:12

ooh my bad, i thought it was already inside functions directory.

darShan
10 Sep, 2023, 08:13

whats the appwrite version? cloud?

bluesky
10 Sep, 2023, 08:16

Yeah, cloud version

darShan
10 Sep, 2023, 08:19

Hmm, the syntax is for 1.4x, Cloud isn't on 1.4x yet.

bluesky
10 Sep, 2023, 08:20

Owh, my bad

bluesky
10 Sep, 2023, 08:20

Do you know how can I debug my code is work or not locally, before I deploy it?

darShan
10 Sep, 2023, 08:25

You could, but there are a few gotchas.

  1. You wouldn't have access to the context, req or res objects locally.
  2. You will have to use env or hardcode your keys / variables & use the function as a normal method call.

Also, this is the pre-1.4x syntax, example function:

TypeScript
import random

def main(req, res):
  print("Hello, Logs!")
  payload = req.payload or 'No payload provided. Add custom data when executing function.'

  secretKey = req.variables.get(
    'SECRET_KEY',
    'SECRET_KEY variable not found. You can set it in Function settings.'
  )

  randomNumber = random.random()

  trigger = req.variables['APPWRITE_FUNCTION_TRIGGER']

  return res.json({
    'message': 'Hello from Appwrite!',
    'payload': payload,
    'secretKey': secretKey,
    'randomNumber': randomNumber,
    'trigger': trigger,
  })
bluesky
10 Sep, 2023, 08:35

Oh it's work

bluesky
10 Sep, 2023, 09:04

So it's not posible if I want to run function locally, or how can I create object like Appwrite function send?

bluesky
10 Sep, 2023, 09:04

This I try to create the object

darShan
10 Sep, 2023, 09:40

payload and variables won't be functions. A Dictionary I'd assume.

Drake
11 Sep, 2023, 21:12

[SOLVED] debug the Python Function

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