Back

Deploying a Collection with Relationships fails

  • 0
  • Databases
Drake
18 Aug, 2023, 01:35

Heh brew installation isn't the best....best to uninstall and install using NPM

TL;DR
Issue: Deploying a collection with relationships fails. The user is experiencing issues with deploying a collection that has relationships. They provided the collections configuration from their 'appwrite.json' file and shared logs from the appwrite-worker-databases container. The error message they received is "Invalid document structure: Unknown attribute: 'relatedCollection'". They also mentioned that when deleting collection1, the relationship attribute in collection2 gets stuck and cannot be deleted properly. Creating new records in collection2 results in the error message "Invalid document structure: Unknown attribute: 'relationship_attribute'". The user attempted to reproduce the issue in a new project and encountered similar
ideclon
18 Aug, 2023, 01:37

After a brew reinstall appwrite, I'm now on 2.0.2

ideclon
18 Aug, 2023, 01:37

Will try a deploy now

ideclon
18 Aug, 2023, 01:39

Yep, that worked - I guess 1.1.1 just didn't understand relationships

ideclon
18 Aug, 2023, 01:39

My first issue still stands, though

Drake
18 Aug, 2023, 01:40

An attribute failed to create? If so, check the docket logs for the appwrite-worker-databases container

ideclon
18 Aug, 2023, 01:42

No, the first issue was when deleting a collection which has an attribute with a relationship, the connected collection is not accessible

Drake
18 Aug, 2023, 01:43

What's the error?

ideclon
18 Aug, 2023, 01:43

500 - general_unknown

ideclon
18 Aug, 2023, 01:44

Appwrite logs say Collection not found

ideclon
18 Aug, 2023, 01:46

Although I tried to reproduce just now, and instead the field in the connected collection just went to undefined

I tried doing another deploy of both collections to make sure I had it set up the same way again, but that failed with βœ— Error Attribute deletion did not finish for too long.

ideclon
18 Aug, 2023, 01:47

And all the records and attributes are gone from collection2 except the connected attribute, which is stuck at "deleting"

ideclon
18 Aug, 2023, 01:54

OK, after starting from scratch with a new project, if collection1 gets deleted, the relationship in collection2 gets "stuck" - it can't be deleted properly, and can't be used, of course.

When creating a new record in collection2, I get the error Invalid document structure: Unknown attribute: "relationship_attribute". If I attempt to delete the relationship, the field no longer comes up when creating new documents, but that error still happens

Drake
18 Aug, 2023, 01:57

What do the appwrite-worker-databases logs say?

ideclon
18 Aug, 2023, 02:01
TypeScript
Attribute not found
[critical] (Job{v1-database} | ID: e3a51dc161ca6f876f939a590bf03771 | DatabaseV1 | <LONG JSON STRING WHICH SEEMS TO BE A REPRESENTATION OF THE COLLECTION>) has failed Utopia\Database\Exception\Structure: Invalid document structure: Unknown attribute: "relatedCollection" in /usr/src/code/vendor/utopia-php/database/src/Database/Database.php:2823
Stack trace:
#0 /usr/src/code/app/workers/databases.php(228): Utopia\Database\Database->updateDocument(Object(Utopia\Database\Document), '1_7_relationship_attribute', Object(Utopia\Database\Document))
#1 /usr/src/code/app/workers/databases.php(44): DatabaseV1->deleteAttribute(Object(Utopia\Database\Document), Object(Utopia\Database\Document), Object(Utopia\Database\Document), '64decb60069911e...')
#2 /usr/src/code/src/Appwrite/Resque/Worker.php(122): DatabaseV1->run()
#3 /usr/src/code/vendor/resque/php-resque/lib/Resque/Job.php(201): Appwrite\Resque\Worker->perform()
#4 /usr/src/code/vendor/resque/php-resque/lib/Resque/Worker.php(303): Resque_Job->perform()
#5 /usr/src/code/vendor/resque/php-resque/lib/Resque/Worker.php(242): Resque_Worker->perform(Object(Resque_Job))
#6 /usr/src/code/vendor/resque/php-resque/bin/resque(185): Resque_Worker->work('0.1', false)
#7 {main}
ideclon
18 Aug, 2023, 02:14

Here's the collections section of my appwrite.json:

ideclon
18 Aug, 2023, 02:14
TypeScript
    "collections": [
        {
            "$id": "collection1",
            "$permissions": [],
            "databaseId": "relationships-test-db",
            "name": "collection1",
            "enabled": true,
            "documentSecurity": false,
            "attributes": [
                {
                    "key": "relationship_attribute",
                    "type": "string",
                    "status": "available",
                    "required": true,
                    "array": false,
                    "size": 20,
                    "default": null
                }
            ],
            "indexes": []
        },
        {
            "$id": "collection2",
            "$permissions": [],
            "databaseId": "relationships-test-db",
            "name": "collection2",
            "enabled": true,
            "documentSecurity": false,
            "attributes": [
                {
                    "key": "relationship_attribute",
                    "type": "relationship",
                    "status": "available",
                    "required": false,
                    "array": false,
                    "relatedCollection": "collection1",
                    "relationType": "manyToOne",
                    "twoWay": false,
                    "twoWayKey": "collection2",
                    "onDelete": "cascade",
                    "side": "parent"
                },
                {
                    "key": "demo_string",
                    "type": "string",
                    "status": "available",
                    "required": false,
                    "array": false,
                    "size": 20,
                    "default": null
                }
            ],
            "indexes": []
        }
    ]
Drake
18 Aug, 2023, 02:16

this happened right after deleting the collection or?

ideclon
18 Aug, 2023, 02:17

I'm not really sure when - I just went to check the logs when you asked about them. I'll go reproduce and check now

Drake
18 Aug, 2023, 02:18

would you be able to create a github issue and in the reproduction steps, put the exat steps?

ideclon
18 Aug, 2023, 02:19

It happened when deleting the attribute

ideclon
18 Aug, 2023, 02:20

Can try if I remember some point next week

Drake
18 Aug, 2023, 02:21

actually, let me see what i can do

Drake
18 Aug, 2023, 02:32
ideclon
18 Aug, 2023, 02:39

Thanks

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