Back

[Error] AppwriteException: general_argument_invalid

  • 0
  • Databases
  • Flutter
  • Functions
conqueror
7 May, 2023, 12:27

trying to create bulk product document, using cloud function, sending product data as json to payload

TL;DR
The user is experiencing an error related to the AppwriteException: general_argument_invalid in their Python code. They are trying to create multiple documents using a for loop, but it is taking too much time. The solution suggested is to make concurrent requests instead of using a loop. The user provided their code snippet and is confused about the suggestion to use client-side functions. They also mentioned potential issues with document IDs and the maximum string size. No specific solution is provided in the thread. However, the user could try implementing concurrent requests using threads or asyncio. They could also explore the suggested feature request for creating documents concurrently in the Appwrite SDK
conqueror
7 May, 2023, 12:28

product data is creation if there is less product but if there is lots of product then its giving this error, here is my code if you want to check Future<void> uploadProducts(List<Map<String, dynamic>> products) async { String payloadString = json.encode({"hallelujah":products}); print(payloadString); Future result = functions.createExecution( functionId: 'upload', data: payloadString, );

Maniac_Fighter
7 May, 2023, 12:38

How long ??

And can you share the uploadFunction on what you are trying to do??

conqueror
7 May, 2023, 12:46

more the 10k products

conqueror
7 May, 2023, 12:46

here in my function ```Future<void> start(final req, final res) async { final client = Client(); final db = Databases(client);

final payload = !req.payload?.isEmpty ? jsonDecode(req.payload) : 'No payload provided. Add custom data when executing function.';

if (req.variables['APPWRITE_FUNCTION_ENDPOINT'] == null || req.variables['APPWRITE_FUNCTION_API_KEY'] == null) { print("Environment variables are not set. Function cannot use Appwrite SDK.");

} else { print(payload["hallelujah"]); client .setEndpoint(req.variables['APPWRITE_FUNCTION_ENDPOINT']) .setProject(req.variables['APPWRITE_FUNCTION_PROJECT_ID']) .setKey(req.variables['APPWRITE_FUNCTION_API_KEY']) .setSelfSigned(status: true); print(req.variables);

TypeScript
try{
  final productData = payload['hallelujah'];
  for(var product in productData){
    await db.createDocument(
        databaseId:'6439e7ae4abb3e14f2b1',
        collectionId: '64444e34a0ce20bc4ac8',
        documentId: "",
        data: product
    );
  }
}catch(e){
  print(e.toString());
}

} res.json({ 'payload': payload, 'areDevelopersAwesome': true, }); } ```

Maniac_Fighter
7 May, 2023, 12:49

so this should fail cause the documentId is empty and it needs an Id

Secondly the error states that the maximum string size it can accept is around 8192 chars and yours would be certainly way more than that

Maniac_Fighter
7 May, 2023, 12:50

One more thing since , you are creating bunch of documents why not use the client side function instead of going through a cloud function?

conqueror
7 May, 2023, 12:50

document id is empty for autogeneration of doc id

conqueror
7 May, 2023, 12:52

how to use client side function

Maniac_Fighter
7 May, 2023, 12:53

You need to use Id.unique() for that for autogeneration

conqueror
7 May, 2023, 12:54

but its creating doc id,

Maniac_Fighter
7 May, 2023, 12:57

I didn't understand what you are trying to say

Vedsaga
7 May, 2023, 12:57
Vedsaga
7 May, 2023, 12:58

what you can do it create document concurrenlty, like 100 doc parllerly

Vedsaga
7 May, 2023, 12:59

should take mostly 1mins max

Vedsaga
7 May, 2023, 13:00

or possibly 100-110 sec, 10000/100 = 100 ( my math xD)

conqueror
7 May, 2023, 13:00

but for this i have to upload the file then retrieve the data

Vedsaga
7 May, 2023, 13:00

no no, for reach document creation you automatically does get document response object

conqueror
7 May, 2023, 13:02

i tried this using for loop which is working but taking too much time ``` for (final product in products) {

try { final document = await database.createDocument( databaseId: '6439e7ae4abb3e14f2b1', collectionId: collectionId, documentId: '', data: product, ); print('Product ${document.data['productName']} uploaded successfully.'); } catch (e) { print('Error uploading product ${product['productName']}: $e'); } }```

Vedsaga
7 May, 2023, 13:02

yap pls don't use loop, try to make concurrent request

Vedsaga
7 May, 2023, 13:03

...

conqueror
7 May, 2023, 13:04

ok let me check and try .

Vedsaga
7 May, 2023, 13:04

that is python code btw

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