Back

[SOLVED] Error while trying to create a document on a cloud function

  • 0
  • Self Hosted
  • Functions
Olivier Pavie
15 Jul, 2023, 20:58

I have been trying to create a document from a cloud function triggered by the web console. It fails ( please check the log image) As you can see, there is "APPWRITE_FUNCTION_USER_ID: " First of all the Id "639d5549a1e8caadcc8d" does not exist anywhere..... and as per the documentation

Executions triggered in the Appwrite console will be prepended with "admin-". This does not happen and i get an ID that does not belong to any user... and that permission issue is confusing me because i thought that an execution from the server is supposed to be trusted?

here is a small code snippet const database = new sdk.Databases(client); console.log("Requesting for base item creation"); let baseItem = await database.createDocument( getSterFashionDbId, fashionItemsCollectionId, sdk.ID.unique(), stringifiedItemData );

I am comfused about this... at first i thought that it was because i was in 1.2.0 but when i updated to 1.3 later on.. got the same issue

TL;DR
Title: [SOLVED] Error creating document on cloud function Solution: The user recreated the API key and the cloud functions started working as usual. There was speculation that the issue was caused by the container being down for 2 months. The issue with the APPWRITE_FUNCTION_USER_ID not matching any existing user was resolved by sharing more code and debugging.
Drake
15 Jul, 2023, 21:30

Please share more of your code

Olivier Pavie
15 Jul, 2023, 21:34

hey, I think i know where the issue was All the cloud functions were failing... I recreated the api key and they're now working as usual

now i am wondering " was it because the container was down for 2 months that the api key stopped working properly?"

Also the issue with the APPWRITE_FUNCTION_USER_ID is strange i use the following line to print it console.log("APPWRITE_FUNCTION_USER_ID:",req.variables.APPWRITE_FUNCTION_USER_ID ); I do not have any user with that ID in my entire project...

Drake
15 Jul, 2023, 21:35

I would only expect the API key to stop working if there was an expiration on it.

If you're executing from the console, the function user id will be the id of the console user, not a project user

Olivier Pavie
15 Jul, 2023, 21:38

They were both set to never... also the <<all>> key access time seems off.. because i changed the api key only 10/15mins ago ... but its ok the console user ID is different

Olivier Pavie
15 Jul, 2023, 21:39

i only have 2 users in the whole project, these are their Ids 63a58376581346983eec 639d6e842201d1f92738 ( logged in with this )

and this is what the console is printing 639d5549a1e8caadcc8d

Olivier Pavie
15 Jul, 2023, 21:45

If you're executing from the console, the function user id will be the id of the console user, not a project user So sorry i did not read properly , my bad πŸ˜…πŸ˜…πŸ˜… you were right, I understood now thanks

Drake
15 Jul, 2023, 21:54

The last accessed at timestamp only updates after 24 hours

Olivier Pavie
15 Jul, 2023, 21:55

ow ok ok i see thanks . by the way, on this current server i have 1.2.0.. can i directly jump to 1.3.7 and run the migration?

Olivier Pavie
15 Jul, 2023, 22:04

i am currently using Gitpod on this old server.... so i can just jump to 1.3 here.... but how do i run the migration at that time πŸ˜… ( sorry for asking so many things... just came back from a very long break... )

Drake
15 Jul, 2023, 22:19

You can jump to 1.3.7 and run the migration

Drake
15 Jul, 2023, 22:19

See the docs

Olivier Pavie
15 Jul, 2023, 22:21

since i am inside gitpod and vscode, can i just switch the branch and run cd appwrite/ docker compose exec appwrite migrate

Olivier Pavie
15 Jul, 2023, 22:22

i mean i am not really sure that it would be appropriate to run docker run -it --rm \ --volume /var/run/docker.sock:/var/run/docker.sock \ --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \ --entrypoint="install" \ appwrite/appwrite:1.3.7 when i can just change the branch??

Drake
15 Jul, 2023, 22:24

Uhh you're running Appwrite from source??

Drake
15 Jul, 2023, 22:24

No you're not.

Drake
15 Jul, 2023, 22:25

Yes, this is the recommended approach but up to you

Olivier Pavie
15 Jul, 2023, 22:26

ok ok will try πŸ™‚ thanks

Olivier Pavie
15 Jul, 2023, 22:32

thats the gitpod... once i open it, it opens vscode ( screenshot above) at that branch(1.2.0) and the browser....

Olivier Pavie
15 Jul, 2023, 22:56

can you please mark the issue as resolved ? πŸ™‚

Drake
15 Jul, 2023, 23:14

You can do it yourself too by editing the post

Drake
15 Jul, 2023, 23:14

[SOLVED] Error while trying to create a document on a cloud 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