Back

[SOLVED] _TypeError for getDocument with Permissions

  • 0
  • Databases
  • Functions
  • Cloud
whataboutno13
19 Sep, 2023, 13:35

Hi there, I am writing a dart function for cloud which basically deletes a document owned by a user and removes read permissions of the users in all other documents in a specific scope. For testing I am creating a document like this:

TypeScript
// Create guestCommObjects for the event
removeGuestCommObject = await database.createDocument(
  databaseId: databaseId,
  collectionId: guestCommObjectCollectionId,
  documentId: removeGuestCommObjectId,
  data: {
    'eventId': event!.$id,
    'userId': removeGuestId,
    'isRegisteredUser': true,
  },
  permissions: [
    Permission.read(Role.user(ownerId)),
    Permission.write(Role.user(ownerId)),
    Permission.delete(Role.user(ownerId)),
    Permission.read(Role.user(guestId1)),
    Permission.read(Role.user(guestId2)),
    Permission.read(Role.user(removeGuestId)),
    Permission.update(Role.user(removeGuestId)),
  ],
);

So far so good, now when I am making this getDocument call:

TypeScript
guestCommObject = await database.getDocument(
  databaseId: privateEventDatabaseId,
  collectionId: guestCommObjectCollectionId,
  documentId: payload['guestCommObjectId'],
);

It throws a _TypeError: '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>'

For me this looks like an error in the Document.fromMap() Error or I am putting these permissions wrong, but why doesnt it throw an exception during create?

TL;DR
The user is getting a `_TypeError` when making a `getDocument` call with permissions. The issue seems to be with the permissions format. The user is creating a document with permissions correctly, but when retrieving the document, it throws the error. The error may be related to the `Document.fromMap()` function or the way permissions are set. The suggested solution is to replace `Permission.write()` with `Permission.update()` and remove `Permission.delete()` if needed.
Drake
19 Sep, 2023, 20:30

would you please replace the Permission.write() with Permission.update()?

whataboutno13
20 Sep, 2023, 08:56

Yes, that did the trick. Or just deleting the Permission.delete() since Permission.write() is update and delete correct?

whataboutno13
20 Sep, 2023, 09:01

But I found it strange that I can create an document which is falsy

Drake
20 Sep, 2023, 16:47

yes correct...I'm pretty sure this was fixed in a newer version of Appwrite

Drake
20 Sep, 2023, 16:47

[SOLVED] _TypeError for getDocument with Permissions

whataboutno13
21 Sep, 2023, 09:30

Alright, thank you Steven! <:appwriteheart2:1073243188954935387>

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