Repository navigation
fix(databases): use project and databases handles correctly when deleting attributes - #14105
Conversation
…ting attributes The worker dispatched deleteAttribute with ($dbForProject, $dbForDatabases) while the method declared ($dbForDatabases, $dbForProject), so every $dbForProject call inside it ran on the databases handle. The body was written against that swap: the physical column/relationship drop happened to land on the right backend, but the attribute/index metadata writes, the two-way related-collection lookup and the collection cache purges also went to the databases handle, and the nested deleteIndex for duplicate indexes received the handles swapped back, dropping the physical index on the project handle. When the databases handle points at the project database (every legacy and TablesDB database in CE) both handles reach the same host, namespace and cache, so nothing changed. When a database lives on its own backend (cloud dedicated databases), the metadata collections do not exist there: the attribute document is never removed, stays in "deleting", and the project's cached collection document keeps listing it. Declare the parameters in the same order as every sibling operation and run the physical drops on the databases handle, so metadata, cache and physical schema each hit the database that owns them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
🟢 Tier S · Ready to merge
Corrects the database-handle order in the attribute-deletion worker to match its dispatcher and sibling operations. Physical attribute and relationship deletion now explicitly use the databases handle, while metadata operations, cache purges, and nested index deletion receive the project handle. Also removes explanatory comments from the index-update block.
📂 Walkthrough · 1
Reviewed |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Bring in main e182a59: #14103 resets the presence created flag on every transaction attempt, #14104 purges the cached collection before a schema change is announced (the race behind the intermittent TablesDB testPatchAttribute 400 column_not_available), and #14105 deletes attributes through the databases handle. Conflicts: - src/Appwrite/Presences/State.php: kept the branch's lookup (userId query with authorization skipped) and took main's per-attempt reset of $presenceCreated, so a retried attempt that updates a concurrent presence no longer reports a creation. - tests/unit/Presences/StateTest.php (added on both sides): union of the branch's permission tests and main's retry tests. main's setUp() is ported to database 8.0 (Collection + Attribute::string instead of the array createCollection/createAttribute with Database::VAR_STRING). The retry test fails when the per-attempt reset is removed. Adaptations: - tests/e2e/Services/Databases/DatabasesBase.php: main's new testCreateIndexOnAttributeAsSoonAsAvailable sent Database::INDEX_KEY, which 8.0 removed; it now sends IndexType::Key->value like the rest of the file. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
Databasesworker dispatchesDATABASE_TYPE_DELETE_ATTRIBUTEasbut
deleteAttributedeclared(…, Database $dbForPlatform, Database $dbForDatabases, Database $dbForProject, …). Inside the method$dbForProjectwas therefore the databases handle and$dbForDatabasesthe project handle. Every other operation (createAttribute,createIndex,deleteIndex,deleteCollection,deleteDatabase) declares and receives(dbForProject, dbForDatabases)in that order; only this one was crossed.Effect
Trace of
deleteAttributeonmain(local name → handle it actually received):getDocument('database_N', relatedCollection)/getDocument('attributes', twoWayKey)deleteRelationship/deleteAttributeondatabase_N_collection_MdeleteDocument/updateDocumentonattributesandindexesdeleteIndexfor a now-duplicate indexpurgeCachedDocument('database_N', …)/purgeCachedCollection(…)Pool::dsn()default branch).Factory::tenant()then builds a handle on the same host, namespace, tenant, shared-tables mode and cache asFactory::project(), so every crossed call reaches the same tables and cache keys. Not observable — no e2e can fail on any configuration CI runs.Appwrite\Cloud\Platform\Workers\Databasescallsparent::action): the databases handle points at the dedicated backend (own schema, empty namespace, own cache name) which has noattributes/indexes/database_Nmetadata collections. The column is dropped, thendeleteDocument('attributes', …)raisesNotFound, theNotFoundhandler retries the same call on the same handle and rethrows, so the attribute document stays indeletingforever; the project's cached collection document is never purged and keeps listing the column; two-way relationships fail on the related-collection lookup before anything is dropped.Fix
Declare
deleteAttribute's handles in the same order as its siblings and the dispatcher, and run the two physical drops (deleteRelationship,deleteAttribute) on$dbForDatabases. Metadata, cache purges and the nesteddeleteIndexcall now receive the handle that owns them. The other dispatch calls in the file were checked and already match their signatures. Narrating comments in the touched method were removed.Test
No regression test: the defect is only reachable when the databases handle targets a different backend than the project handle, which no CE configuration produces for databases that support attribute deletion (see trace above), and worker internals are covered by e2e only. Existing attribute/column deletion e2e suites (Legacy, TablesDB, including relationship and index-rebuild cases) exercise the corrected path and must stay green. Full PHPStan passes locally.
🤖 Generated with Claude Code