Skip to content
Back

DocumentList throwing exception

  • 0
  • Databases
Arrow
26 Dec, 2024, 16:28

Hello, I am trying to read docs from locally hosted appwrite. DocumentList throws no error if there is no document, and when i add a doc the following exception throws

TypeScript
#0      new Document.fromMap (package:appwrite/src/models/document.dart:41:42)
#1      new DocumentList.fromMap.<anonymous closure> (package:appwrite/src/models/document_list.dart:20:68)
#2      MappedListIterable.elementAt (dart:_internal/iterable.dart:435:31)
#3      ListIterator.moveNext (dart:_internal/iterable.dart:364:26)
#4      new List.from (dart:core-patch/array_patch.dart:29:17)
#5      new DocumentList.fromMap (package:appwrite/src/models/document_list.dart:20:11)
#6      Databases.listDocuments (package:appwrite/services/databases.dart:33:32)
<asynchronous suspension>
#7      main (package:pharmalytics/main.dart:15:13)
<asynchronous suspension>
TL;DR
Issue: When attempting to read documents from a locally hosted Appwrite, DocumentList throws an exception due to a mismatch in data types for permissions. Solution: Update the code snippet to correctly handle incoming permission data as a List of dynamic types: ``` $permissions: (List.from(map['\$permissions']) ?? <String>[]), ``` GitHub open issue for reference: https://github.com/appwrite/appwrite/issues/9116
Arrow
26 Dec, 2024, 16:30
TypeScript

final db = client.databases;

final k = await db.listDocuments(databaseId: '6765d0e500231e6fff09', collectionId: '6765d1160000b344e358');

print(k.documents); // throws```
Arrow
26 Dec, 2024, 16:53
Arrow
26 Dec, 2024, 17:15

looks like the following from appwrite sdk is the issue

TypeScript
    return Document(
      $id: map['\$id'].toString(),
      $collectionId: map['\$collectionId'].toString(),
      $databaseId: map['\$databaseId'].toString(),
      $createdAt: map['\$createdAt'].toString(),
      $updatedAt: map['\$updatedAt'].toString(),
      $permissions: map['\$permissions'] ?? [],
      data: map,
    );
  }```

something like this fixed the issue because the incoming permision data from the map is actually of List dynamic
```  $permissions: (List.from(map['\$permissions']) ?? <String>[]),```
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