Back

Error when updating a string attribute using dart sdk

  • 2
  • Flutter
  • Web
  • Databases
  • Cloud
  • Self Hosted
Shivanshu Gupta
11 Oct, 2024, 15:37

AppwriteException: general_argument_invalid, Param "default" is not optional. (400)

TL;DR
Error occurs when attempting to update a string attribute's default value in Dart SDK due to the value being required, not allowing it to be set to null. To solve this, the `xdefault` parameter should be handled differently when `attributeA.required` is true to avoid setting it to null, which results in an error.
Raman
11 Oct, 2024, 15:37

cc: @D5 We are using dart-sdk for performing this sync

Shivanshu Gupta
11 Oct, 2024, 15:39

Here is a code snippet for the same:

TypeScript
await dest.databases.updateStringAttribute(
  databaseId: databaseId,
  collectionId: collectionId,
  key: attributeA.key,
  size: attributeA.size!,
  xrequired: attributeA.required,
  xdefault:
      attributeA.required ? null : (attributeA.defaultValue ?? ''),
);
Shivanshu Gupta
11 Oct, 2024, 15:42

if I write the xdefault part like this:

TypeScript
xdefault: attributeA.defaultValue ?? '',

I get this error: AppwriteException: attribute_default_unsupported, Cannot set default value for required attribute (400)

D5
11 Oct, 2024, 15:59

Hmm I think it can't be nul as it needs to be true or false?

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