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: Limbo Attribute if Related Collection is Deleted #6012

Closed
2 tasks done
stnguyen90 opened this issue Aug 18, 2023 · 6 comments · Fixed by utopia-php/database#371
Closed
2 tasks done
Assignees
Labels
bug Something isn't working feature / relationships Fixes and upgrades for database relationships product / databases Fixes and upgrades for the Appwrite Database.

Comments

@stnguyen90
Copy link
Contributor

stnguyen90 commented Aug 18, 2023

👟 Reproduction steps

  1. Create collection level1
  2. Create collection level2
  3. Create attribute in level1
    • type: relationship
    • one/two way: one way
    • key: level2
    • related collection: level2
    • relation: Many to One
    • on deleting: Cascade
  4. Delete collection level2
  5. Delete attribute level2 from collection level1

👍 Expected behavior

The attribute gets deleted

👎 Actual Behavior

Attribute is stuck at deleting:

image

appwrite-worker-databases logs:

appwrite-worker-databases  | [notice] Starting work on (Job{v1-database} | ID: 1bfcd72ea4d3b9e2c14336caf462eeac | DatabaseV1 | [{"project":{"teamId":"63225d9cbfcbdd156fea","name":"Nested Creates","description":"","logo":"","url":"","version":"1.3.0","legalName":"","legalCountry":"","legalState":"","legalCity":"","legalAddress":"","legalTaxId":"","services":[],"auths":{"passwordHistory":0,"passwordDictionary":false,"limit":0,"maxSessions":10,"duration":31536000,"emailPassword":true,"usersAuthMagicURL":true,"anonymous":true,"invites":true,"JWT":true,"phone":true},"authProviders":false,"platforms":[],"webhooks":[],"keys":[],"domains":[],"search":"nested-creates Nested Creates","teamInternalId":"125","region":"default","$id":"nested-creates","$internalId":"200","$createdAt":"2023-06-01T18:47:35.194+00:00","$updatedAt":"2023-07-18T21:47:37.827+00:00","$permissions":["read(\"team:63225d9cbfcbdd156fea\")","update(\"team:63225d9cbfcbdd156fea\/owner\")","update(\"team:63225d9cbfcbdd156fea\/developer\")","delete(\"team:63225d9cbfcbdd156fea\/owner\")","delete(\"team:63225d9cbfcbdd156fea\/developer\")"],"$collection":"projects"},"user":null,"type":"deleteAttribute","collection":{"databaseInternalId":"3","databaseId":"many-to-one","name":"level1","enabled":true,"documentSecurity":false,"attributes":[{"databaseInternalId":"3","databaseId":"many-to-one","collectionInternalId":"4","collectionId":"level1","key":"level2","type":"relationship","status":"available","size":0,"required":false,"default":null,"signed":true,"array":false,"format":"","formatOptions":[],"filters":[],"$id":"3_4_level2","$internalId":"21","$createdAt":"2023-08-18T02:24:48.022+00:00","$updatedAt":"2023-08-18T02:24:48.265+00:00","$permissions":[],"$collection":"attributes","relatedCollection":"level2","relationType":"manyToOne","twoWay":false,"twoWayKey":"level1","onDelete":"cascade","side":"parent"}],"indexes":[],"search":"level1 level1","$id":"level1","$internalId":"4","$createdAt":"2023-08-18T02:23:13.439+00:00","$updatedAt":"2023-08-18T02:23:13.439+00:00","$permissions":[],"$collection":"database_3"},"document":{"databaseInternalId":"3","databaseId":"many-to-one","collectionInternalId":"4","collectionId":"level1","key":"level2","type":"relationship","status":"deleting","size":0,"required":false,"default":null,"signed":true,"array":false,"format":"","formatOptions":[],"filters":[],"options":{"relatedCollection":"level2","relationType":"manyToOne","twoWay":false,"twoWayKey":"level1","onDelete":"cascade","side":"parent"},"$id":"3_4_level2","$internalId":"21","$createdAt":"2023-08-18T02:24:48.022+00:00","$updatedAt":"2023-08-18T02:26:44.240+00:00","$permissions":[],"$collection":"attributes","relatedCollection":null,"relationType":"","twoWay":false,"twoWayKey":"","onDelete":"restrict","side":""},"database":{"name":"many-to-one","search":"many-to-one many-to-one","$id":"many-to-one","$internalId":"3","$createdAt":"2023-08-18T02:13:06.924+00:00","$updatedAt":"2023-08-18T02:13:06.924+00:00","$permissions":[],"$collection":"databases"},"events":["."]}])
appwrite-worker-databases  | Attribute not found
appwrite-worker-databases  | [critical] (Job{v1-database} | ID: 1bfcd72ea4d3b9e2c14336caf462eeac | DatabaseV1 | [{"project":{"teamId":"63225d9cbfcbdd156fea","name":"Nested Creates","description":"","logo":"","url":"","version":"1.3.0","legalName":"","legalCountry":"","legalState":"","legalCity":"","legalAddress":"","legalTaxId":"","services":[],"auths":{"passwordHistory":0,"passwordDictionary":false,"limit":0,"maxSessions":10,"duration":31536000,"emailPassword":true,"usersAuthMagicURL":true,"anonymous":true,"invites":true,"JWT":true,"phone":true},"authProviders":false,"platforms":[],"webhooks":[],"keys":[],"domains":[],"search":"nested-creates Nested Creates","teamInternalId":"125","region":"default","$id":"nested-creates","$internalId":"200","$createdAt":"2023-06-01T18:47:35.194+00:00","$updatedAt":"2023-07-18T21:47:37.827+00:00","$permissions":["read(\"team:63225d9cbfcbdd156fea\")","update(\"team:63225d9cbfcbdd156fea\/owner\")","update(\"team:63225d9cbfcbdd156fea\/developer\")","delete(\"team:63225d9cbfcbdd156fea\/owner\")","delete(\"team:63225d9cbfcbdd156fea\/developer\")"],"$collection":"projects"},"user":null,"type":"deleteAttribute","collection":{"databaseInternalId":"3","databaseId":"many-to-one","name":"level1","enabled":true,"documentSecurity":false,"attributes":[{"databaseInternalId":"3","databaseId":"many-to-one","collectionInternalId":"4","collectionId":"level1","key":"level2","type":"relationship","status":"available","size":0,"required":false,"default":null,"signed":true,"array":false,"format":"","formatOptions":[],"filters":[],"$id":"3_4_level2","$internalId":"21","$createdAt":"2023-08-18T02:24:48.022+00:00","$updatedAt":"2023-08-18T02:24:48.265+00:00","$permissions":[],"$collection":"attributes","relatedCollection":"level2","relationType":"manyToOne","twoWay":false,"twoWayKey":"level1","onDelete":"cascade","side":"parent"}],"indexes":[],"search":"level1 level1","$id":"level1","$internalId":"4","$createdAt":"2023-08-18T02:23:13.439+00:00","$updatedAt":"2023-08-18T02:23:13.439+00:00","$permissions":[],"$collection":"database_3"},"document":{"databaseInternalId":"3","databaseId":"many-to-one","collectionInternalId":"4","collectionId":"level1","key":"level2","type":"relationship","status":"deleting","size":0,"required":false,"default":null,"signed":true,"array":false,"format":"","formatOptions":[],"filters":[],"options":{"relatedCollection":"level2","relationType":"manyToOne","twoWay":false,"twoWayKey":"level1","onDelete":"cascade","side":"parent"},"$id":"3_4_level2","$internalId":"21","$createdAt":"2023-08-18T02:24:48.022+00:00","$updatedAt":"2023-08-18T02:26:44.240+00:00","$permissions":[],"$collection":"attributes","relatedCollection":null,"relationType":"","twoWay":false,"twoWayKey":"","onDelete":"restrict","side":""},"database":{"name":"many-to-one","search":"many-to-one many-to-one","$id":"many-to-one","$internalId":"3","$createdAt":"2023-08-18T02:13:06.924+00:00","$updatedAt":"2023-08-18T02:13:06.924+00:00","$permissions":[],"$collection":"databases"},"events":["."]}]) 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
appwrite-worker-databases  | Stack trace:
appwrite-worker-databases  | #0 /usr/src/code/app/workers/databases.php(228): Utopia\Database\Database->updateDocument(Object(Utopia\Database\Document), '3_4_level2', Object(Utopia\Database\Document))
appwrite-worker-databases  | #1 /usr/src/code/app/workers/databases.php(44): DatabaseV1->deleteAttribute(Object(Utopia\Database\Document), Object(Utopia\Database\Document), Object(Utopia\Database\Document), 'nested-creates')
appwrite-worker-databases  | #2 /usr/src/code/src/Appwrite/Resque/Worker.php(122): DatabaseV1->run()
appwrite-worker-databases  | #3 /usr/src/code/vendor/resque/php-resque/lib/Resque/Job.php(201): Appwrite\Resque\Worker->perform()
appwrite-worker-databases  | #4 /usr/src/code/vendor/resque/php-resque/lib/Resque/Worker.php(303): Resque_Job->perform()
appwrite-worker-databases  | #5 /usr/src/code/vendor/resque/php-resque/lib/Resque/Worker.php(242): Resque_Worker->perform(Object(Resque_Job))
appwrite-worker-databases  | #6 /usr/src/code/vendor/resque/php-resque/bin/resque(185): Resque_Worker->work('0.1', false)
appwrite-worker-databases  | #7 {main}

Discord Thread: https://discord.com/channels/564160730845151244/1141837364575076462

🎲 Appwrite version

Version 1.3.x

💻 Operating system

Linux

🧱 Your Environment

Appwrite 1.3.8

👀 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 stnguyen90 added bug Something isn't working product / databases Fixes and upgrades for the Appwrite Database. labels Aug 18, 2023
@Akshay-Rana-Gujjar
Copy link
Contributor

Hello @stnguyen90, could you please assign this issue to me. Thanks

@Haimantika
Copy link
Contributor

Hello @stnguyen90, could you please assign this issue to me. Thanks

Assigning it to you.

@Akshay-Rana-Gujjar
Copy link
Contributor

Hello @stnguyen90, could you please assign this issue to me. Thanks

Assigning it to you.

Thanks, will start working on it by tomorrow.

@Akshay-Rana-Gujjar
Copy link
Contributor

Raised the MR, kindly review.

Thanks

@drraghavendra
Copy link

fix: delete attribute even if related collection does not exist

This pull request fixes an issue where deleting an attribute from a document would fail if the related collection did not exist. This could happen if the collection had been deleted since the attribute was created.

@stnguyen90 stnguyen90 added the feature / relationships Fixes and upgrades for database relationships label Dec 20, 2023
@fogelito
Copy link
Contributor

PR created
utopia-php/database#371

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

Successfully merging a pull request may close this issue.

5 participants