Skip to content
Back

Function Event wildcards caused infinite loop causing 500 Internal error

  • 0
  • Databases
  • React Native
  • Cloud
PA
9 Jun, 2025, 12:39

Hi guys @Support
I created a function to be triggered everytime an item is added or checked state changed in items collection it update the list collection total_items and checked_items

See code

export default async ({ req, res, log, error }) => { const key = req.headers['x-appwrite-key']; const client = new Client() .setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT) .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) .setKey(key);

const databases = new Databases(client);

// ENV variables for collection IDs const databaseId = process.env.APPWRITE_DATABASE_ID; const listsCollectionId = process.env.APPWRITE_LISTS_COLLECTION_ID; const itemsCollectionId = process.env.APPWRITE_ITEMS_COLLECTION_ID;

try { // Get all lists const listDocs = await databases.listDocuments(databaseId, listsCollectionId);

TypeScript
for (const list of listDocs.documents) {
  const listId = list.$id;

  // Fetch all items for this list
  const allItems = await databases.listDocuments(databaseId, itemsCollectionId, [
    Query.equal('list_id', listId)
  ]);

  const totalItems = allItems.total;
  const checkedItems = allItems.documents.filter(item => item.checked === true).length;

  // Update the list document with the new counts
  await databases.updateDocument(databaseId, listsCollectionId, listId, {
    items_total: totalItems,
    items_checked: checkedItems
  });

 
}

return res.json({ success: true, message: 'All lists updated.' });

} catch (err) { error('Failed to update list counts: ' + err.message); return res.json({ success: false, error: err.message }); } };

I then added wildcards events that has caused infinite which has made my Appwrite Project blocked due to an excessive amount of function executions

["databases..collections..documents.*.create", ….] I can not access to my project to update the events. Can i get some help ?

TL;DR
Function Event wildcards causing infinite loop led to a 500 Internal error. The issue was flagged and blocked due to recursive behavior. Support team is working on it. The developer created a function that updates counts in a collection based on item changes. Wildcards events caused an infinite loop and project was blocked. They need help accessing the project to update the events.
eldad
9 Jun, 2025, 12:41

@PA as mentioned on the email sent to you by the support team your function has been flagged and blocked to prevent your project from a billing bomb or excessive usage do to the recursive behavior you've implemented.

Our support team is already in contact with you and will help you understand how to prevent this and unpause your usage.

PA
9 Jun, 2025, 12:53

Appreciate the quick response.

I will wait for a reply from support and hope to resolve this asa from my side.

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