Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃殌 Feature: Allow document general attributes on update #4802

Open
2 tasks done
silberGuy opened this issue Nov 29, 2022 · 3 comments
Open
2 tasks done

馃殌 Feature: Allow document general attributes on update #4802

silberGuy opened this issue Nov 29, 2022 · 3 comments
Labels
product / databases Fixes and upgrades for the Appwrite Database.

Comments

@silberGuy
Copy link

silberGuy commented Nov 29, 2022

馃敄 Feature description

When updating a document from my web app, sometimes we update the document object itself and pass it whole to the update function.
This procedure (which worked before updating from 0.14 to 1.1) now throws the following:

AppwriteException: Invalid document structure: Unknown attribute: "$collectionId"
    at Client.<anonymous> (http:https://localhost:3333/node_modules/.vite/deps/appwrite.js?v=61b2c4de:775:17)
    at Generator.next (<anonymous>)
    at fulfilled (http:https://localhost:3333/node_modules/.vite/deps/appwrite.js?v=61b2c4de:488:24)

I think that in case that the user of the update function is not trying to change this property, the backend can ignore it.

馃帳 Pitch

I guess that in general, attributes like $collectionId should not be used, for the $ prefix indicates a system-level property.
My current solution was to filter-out the property, and also $permissions, $id and similar, on client-side level, and his could be spared.

馃憖 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

馃彚 Have you read the Code of Conduct?

@stnguyen90
Copy link
Contributor

@silberGuy thanks for raising this issue! Could you please provide sample code for this?

@stnguyen90 stnguyen90 added the product / databases Fixes and upgrades for the Appwrite Database. label Dec 1, 2022
@silberGuy
Copy link
Author

silberGuy commented Dec 4, 2022

Well, I am not much of a PHP dev,
my client side JS code looks similar to the following:

async function updateDoc(collectionId: string, docId: string, docData: Partial<DocType>, permissions?: string[]) {
  const updateData = {
      ...docData,
      id: undefined,
      $collectionId: undefined,
      $createdAt: undefined,
      $databaseId: undefined,
      $id: undefined,
      $permissions: undefined,
  }
  return await appwriteDbs.updateDocument(
    'default', collectionId, docId, updateData, permissions,
  )
}

and I would love to just use:

async function updateDoc(collectionId: string, docId: string, docData: Partial<DocType>, permissions?: string[]) {
  return await appwriteDbs.updateDocument(
    'default', collectionId, docId, docData, permissions,
  )
}

I guess we can add similar filtering logic in the JS sdk.
But, I think that to solve this for all sdks (I did not use any other though), better solutions could be:

  • The server would filter out these keys
  • The server would throw only when the client attempts to change their values

@JakeAi
Copy link

JakeAi commented Jan 10, 2023

@stnguyen90 I agree with @silberGuy. It used to be this way. Now I can send all of the "$" attributes except $databaseId and $collectionId... pick a theme and stick to it please. Having to remove all of the $attributes before updating a document in so many different areas is tiresome and repeating and too many areas to miss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product / databases Fixes and upgrades for the Appwrite Database.
Projects
None yet
Development

No branches or pull requests

3 participants