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/9116TypeScript
final db = client.databases;
final k = await db.listDocuments(databaseId: '6765d0e500231e6fff09', collectionId: '6765d1160000b344e358');
print(k.documents); // throws```
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>[]),```
Recommended threads
- Does 1.9.0 Self Hosted have MongoDB Atla...
I have been playing with the new 1.9.0 update and I am really excited for the MongoDB support. I wanted to ask though if at the current time Appwrite supports b...
- {"code": 1008, "message": "Invalid Origi...
Nothing has changed in my application or console settings so I'm curious as to what I need to do to fix this. I already have the client registered so I'm not en...
- NEW ERROR Invalid document structure: At...
Error: ```AppwriteException: document_invalid_structure, Invalid document structure: Attribute "pb.kmsgxPkgInfo.id_info" must be an array (400)``` I’m encounter...