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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Bug Report: 500 error setting relationship to empty array #6989

Closed
2 tasks done
Kunalgoel9 opened this issue Oct 23, 2023 · 3 comments
Closed
2 tasks done

🐛 Bug Report: 500 error setting relationship to empty array #6989

Kunalgoel9 opened this issue Oct 23, 2023 · 3 comments
Assignees
Labels
bug Something isn't working product / databases Fixes and upgrades for the Appwrite Database.

Comments

@Kunalgoel9
Copy link

Kunalgoel9 commented Oct 23, 2023

👟 Reproduction steps

I have two collections in my servers one is users and other is leads

I created a Relationship between them as many to one like this
image

Now the issue i am facing is while creating a new account of user Server 500 error occurs
Code:

 async createAccount({
    email,
    password,
    name,
  }: {
    email: string;
    password: string;
    name: string;
  }): Promise<any> {
    try {
      const userAccount = await this.account.create(
        ID.unique(),
        email,
        password,
        name
      );
      const data = JSON.stringify({
        userid: userAccount.$id,
        name: name,
        email: email,
        leads:[ ]<-------------  I think i am not able to send the empty leads relationship field
      });

      const usersdata = await database.createDocument(
        conf.appwriteDatabaseId,
        conf.appwriteUsersCollectionId,
        ID.unique(),
        data
      );
      await this.account.createEmailSession(email, password);

      const res = await this.account.createVerification(
        `${conf.appwriteclientURL}/verify`
      );

      if (userAccount && res) {
        return { userAccount: userAccount, res: res };
      }
    } catch (error: any) {
      console.log(error.message);

           throw error;
    }
  }

The main issue i think is i am adding users after authentication and i am not sendings the leads attribute relationship in data but i want the leads to be empty annd not bieng able to send the leads attribute as empty array

👍 Expected behavior

It Should Create a new Document white empty leads

👎 Actual Behavior

It Gives Server error 500

🎲 Appwrite version

Appwrite Cloud

💻 Operating system

Windows

🧱 Your Environment

Appwrite verision in console-->4.1.0
Appwrite library version in package.json
"appwrite": "^13.0.0"

i am using appwrite web SDK and i am currently using ReactJS as my frontend development

👀 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?

@Kunalgoel9 Kunalgoel9 added the bug Something isn't working label Oct 23, 2023
@stnguyen90 stnguyen90 changed the title 🐛 Bug Report: 🐛 Bug Report: 500 error setting relationship to empty array Oct 23, 2023
@stnguyen90 stnguyen90 self-assigned this Oct 23, 2023
@stnguyen90 stnguyen90 added the product / databases Fixes and upgrades for the Appwrite Database. label Oct 23, 2023
@stnguyen90
Copy link
Contributor

@Kunalgoel9, thanks for creating this issue! 🙏🏼 A couple things to try:

  1. No need to JSON.stringify() the data
  2. You have a Many to One, which means a single user has a single lead. In the description of the attribute you can see "users can contain one leads". As such, please try passing null instead of an empty array. Otherwise, you may want to recreate the attribute as either a Many to Many or a One to Many depending on your requirements.

@fatherofinvention
Copy link

@Kunalgoel9 I faced the same issue. It is a permission issue. My permissions were set correctly on the collection I was trying to access but not correct on the related collection. Making the permission settings match between collections resolved the issue. This was harder than it needed to be due to the API returning a generic error, but once you make this correction it will resolve the issue.

A little example:
{"data":{"title":"Sample Title","ageDays":10,"status":"mycoolstatus","modified":"2023-11-11T16:58:56+00:00","type":"madeupexample","created":"2023-11-11T16:58:56+00:00","description":"This is a detailed description of the widget.","due":"2023-11-11T18:22:16+00:00","instock":false,"priority":"urgent","comments":[]},"permissions":["read(\"label:admin\")"],"documentId":"unique()"}

Notice here I am passing an empty array to the related comments table. Problem was, I didn't have my permissions set there like I did on the main collection. Notice the permission I passed in? You need label:admin on the main table, but I didn't realize that it needed to be set on the related comments table.

@stnguyen90 for visibility.

@stnguyen90
Copy link
Contributor

Closing stale issue

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

No branches or pull requests

3 participants