Back

Bug with $permissions in document

  • 1
  • Self Hosted
  • Databases
  • Cloud
otik
3 Jun, 2023, 18:12

I solved it by converting object into array, Thank you for helping me

TL;DR
User is experiencing a bug with permissions in a document. They are seeing duplicate data in the permissions array after updating the document. Another user suggests not passing duplicate data. The user provides code and console output showing the issue. They mention that they cannot reproduce the issue themselves. The user also mentions that after updating, they are unable to open the document in the console. They provide the permissions before and after updating the document. Another user asks for more specific information to reproduce the issue. The original user mentions that they solved the problem by converting an object into an array. No specific solution is provided in the thread. Solution: The original user solved
Drake
3 Jun, 2023, 18:41

I'd really like to figure out how it happened so that we could prevent it from happening again, but I can't reproduce the problem

otik
3 Jun, 2023, 19:00

Did you here updated the document or creating it?

Drake
3 Jun, 2023, 19:14

Both

Drake
3 Jun, 2023, 19:16

What were the permissions on the created document before updating?

otik
3 Jun, 2023, 20:11

It was normal string[], everything is ok till i update the document, then it breaks.....it is weird that it happends to me every single time and for you it works properly

Drake
3 Jun, 2023, 20:13

Exact value would be helpful so I could try and reproduce

otik
4 Jun, 2023, 09:38

Before i update the document, incoming permissions look like this: permissions: [ 'read("any")', 'read("user:642090ce0b988edac790")', 'read("user:642090ce0b988edac790")', 'write("user:642090ce0b988edac790")', 'update("user:642090ce0b988edac790")', 'delete("user:642090ce0b988edac790")' ]

otik
4 Jun, 2023, 09:39
otik
4 Jun, 2023, 09:40

then when i getDocument, it comes like this:

otik
4 Jun, 2023, 09:40

"$permissions": { "0": "read(any)", "1": "read(user:642090ce0b988edac790)", "3": "update(user:642090ce0b988edac790)", "4": "delete(user:642090ce0b988edac790)" },

otik
4 Jun, 2023, 09:45
Drake
4 Jun, 2023, 15:56

No I meant what was the permissions on the document before you updated it

otik
4 Jun, 2023, 19:21

Yes, sorry for misunderstanding, these are permissions before i update the document -$permissions: [ 'read("any")', 'read("user:642090ce0b988edac790")', 'update("user:642090ce0b988edac790")', 'delete("user:642090ce0b988edac790")' ]

Then, when i update that document and when i load that document, i get this: "$permissions": { "0": "read("any")", "1": "read("user:642090ce0b988edac790")", "3": "update("user:642090ce0b988edac790")", "4": "delete("user:642090ce0b988edac790")" },

otik
4 Jun, 2023, 20:08

After updating i cant event open document in console (cloud.appwrite.io)

otik
4 Jun, 2023, 20:08

even*

Drake
5 Jun, 2023, 01:09

i still can't reproduce. this is my code:

TypeScript
    const initialPermissions = [
        'read("any")',
        'read("user:642090ce0b988edac790")',
        'update("user:642090ce0b988edac790")',
        'delete("user:642090ce0b988edac790")'
    ];

    console.log(initialPermissions);

    const created = await databases.createDocument(
        'default',
        'test',
        'permission',
        {
            b: true
        },
        initialPermissions
    );

    console.log(created);

    const updatedPermissions = [
        'read("any")',
        'read("user:642090ce0b988edac790")',
        'read("user:642090ce0b988edac790")',
        'write("user:642090ce0b988edac790")',
        'update("user:642090ce0b988edac790")',
        'delete("user:642090ce0b988edac790")'
    ]

    const updated = await databases.updateDocument(
        'default',
        'test',
        created.$id,
        {
            b: false,
        },
        updatedPermissions
    );

    console.log(updated);
Drake
5 Jun, 2023, 01:10

this is the output:

TypeScript
[
  'read("any")',
  'read("user:642090ce0b988edac790")',
  'update("user:642090ce0b988edac790")',
  'delete("user:642090ce0b988edac790")'
]
{
  b: true,
  '$id': 'permission',
  '$permissions': [
    'read("any")',
    'read("user:642090ce0b988edac790")',
    'update("user:642090ce0b988edac790")',
    'delete("user:642090ce0b988edac790")'
  ],
  '$createdAt': '2023-06-05T01:09:10.059+00:00',
  '$updatedAt': '2023-06-05T01:09:10.059+00:00',
  s: 'default value',
  i: null,
  '$collectionId': 'test',
  '$databaseId': 'default'
}
{
  b: false,
  s: 'default value',
  i: null,
  '$id': 'permission',
  '$createdAt': '2023-06-05T01:09:10.059+00:00',
  '$updatedAt': '2023-06-05T01:09:10.617+00:00',
  '$permissions': [
    'read("any")',
    'read("user:642090ce0b988edac790")',
    'read("user:642090ce0b988edac790")',
    'update("user:642090ce0b988edac790")',
    'delete("user:642090ce0b988edac790")',
    'update("user:642090ce0b988edac790")',
    'delete("user:642090ce0b988edac790")'
  ],
  '$collectionId': 'test',
  '$databaseId': 'default'
}
otik
5 Jun, 2023, 06:27

Are you using node-appwrite version 9.0.0?

Drake
5 Jun, 2023, 12:43

Yep

Drake
5 Jun, 2023, 14:37

wait a minute! the result of updateDocument() for me was right, but then if i getDocument() again, it shows the problem

Drake
5 Jun, 2023, 14:51
otik
5 Jun, 2023, 17:18

What do you suggest me to do now? I cant continue programming

Drake
5 Jun, 2023, 17:21

i suggest not passing duplicate data (the extra read and the write permissions)

otik
5 Jun, 2023, 17:26

Oh, ok thank you for helping

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