Skip to content
Back

User object empty preferences is an array instead of an object

  • 0
  • Users
  • Functions
darkmess
28 Sep, 2023, 08:59

According to the docs, the prefs field should be an object but when I get it from functions it's an array

https://appwrite.io/docs/models/user

{"$id":"65153d362dcf3f9f27bf","$createdAt":"2023-09-28T08:45:42.189 00:00","$updatedAt":"2023-09-28T08:45:42.189 00:00","name":"sdfdfdf","registration":"2023-09-28T08:45:42.187 00:00","status":true,"labels":[],"passwordUpdate":"2023-09-28T08:45:42.187 00:00","email":"dfsdsf@dssd.adsasd","phone":"","emailVerification":false,"phoneVerification":false,"prefs":[],"accessedAt":"2023-09-28T08:45:42.187 00:00"}

TL;DR
User object preferences is an array instead of an object. The bug may be elsewhere, so it's recommended to create a GitHub issue. Use backticks to format code. The function Users.FromMap() fails because the preferences in the user object is an array instead of an object. The user object is received from context.req.body. The code version is Dart 2.17 and SDK 8.0.0. There is no obvious reason in the code for this issue. The user preferences should be an object according to the documentation.
loks0n
28 Sep, 2023, 09:04

Hey 👋

loks0n
28 Sep, 2023, 09:05

What SDK are you using?

darkmess
28 Sep, 2023, 09:08

Dart server SDK

loks0n
28 Sep, 2023, 09:11

Weird can't see any obvious reason for this in the code.

What version of dart and dart SDK are you running?

darkmess
28 Sep, 2023, 09:15

Dart 2.17 SDK 8.0.0

darkmess
28 Sep, 2023, 09:17

To give you some context, this is the function it's triggered by an users.*.delete event

Future<dynamic> main(final context) async { final client = Client() .setEndpoint(Platform.environment['APPWRITE_ENDPOINT']!) .setProject(Platform.environment['APPWRITE_FUNCTION_PROJECT_ID']) .setKey(Platform.environment['API_KEY']); try { final user = User.fromMap(context.req.body); await Databases(client).deleteDocument( databaseId: Platform.environment['DATABASE_ID']!, collectionId: Platform.environment['USERS_COLLECTION_ID']!, documentId: user.$id, ); return context.res.empty(); } on Exception catch (e, stack) { context.error('$e \n $stack'); return context.res.send('Server error', 500); }

darkmess
28 Sep, 2023, 09:17

Sorry I can't format it on mobile

darkmess
28 Sep, 2023, 09:18

Users.FromMap() fails because the user object from context.req.body preferences is an array instead of an object

Drake
28 Sep, 2023, 17:41

FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.

Drake
28 Sep, 2023, 17:43

weird....we should be converting it if it's empty...but maybe the bug is somewhere else. Would you be able to create a GitHub issue for this?

darkmess
29 Sep, 2023, 12:26

Done

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