Skip to content

fix(databases): use project and databases handles correctly when deleting attributes - #14105

Merged
abnegate merged 1 commit into
mainfrom
fix-delete-attribute-handles
Oct 5, 2026
Merged

abnegate merged 1 commit into
mainfrom
fix-delete-attribute-handles

Conversation

@abnegate

@abnegate abnegate commented Oct 5, 2026

Copy link
Copy Markdown
Member

Problem

Databases worker dispatches DATABASE_TYPE_DELETE_ATTRIBUTE as

$this->deleteAttribute($database, $collection, $document, $project, $dbForPlatform, $dbForProject, $dbForDatabases, $queueForRealtime)

but deleteAttribute declared (…, Database $dbForPlatform, Database $dbForDatabases, Database $dbForProject, …). Inside the method $dbForProject was therefore the databases handle and $dbForDatabases the 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 deleteAttribute on main (local name → handle it actually received):

Operation Belongs on Ran on
getDocument('database_N', relatedCollection) / getDocument('attributes', twoWayKey) project databases
deleteRelationship / deleteAttribute on database_N_collection_M databases databases (right only because of the swap)
deleteDocument / updateDocument on attributes and indexes project databases
nested deleteIndex for a now-duplicate index physical on databases, metadata on project physical on project, metadata on databases (swapped back)
purgeCachedDocument('database_N', …) / purgeCachedCollection(…) project databases
  • CE (all CI lanes): attribute deletion is only exposed for legacy and TablesDB databases, whose DSN is the project DSN (Pool::dsn() default branch). Factory::tenant() then builds a handle on the same host, namespace, tenant, shared-tables mode and cache as Factory::project(), so every crossed call reaches the same tables and cache keys. Not observable — no e2e can fail on any configuration CI runs.
  • Cloud dedicated databases (Appwrite\Cloud\Platform\Workers\Databases calls parent::action): the databases handle points at the dedicated backend (own schema, empty namespace, own cache name) which has no attributes/indexes/database_N metadata collections. The column is dropped, then deleteDocument('attributes', …) raises NotFound, the NotFound handler retries the same call on the same handle and rethrows, so the attribute document stays in deleting forever; 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 nested deleteIndex call 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

…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]>
@ghost

ghost commented Oct 5, 2026

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The corrected signature matches its caller, and physical and metadata operations use the appropriate handles without introducing a concrete regression.

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.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 1
File Change
src/Appwrite/Platform/Modules/Databases/Workers/Databases.php Aligns deleteAttribute handle ordering and routes physical schema drops to dbForDatabases; removes index-block comments.

Reviewed e570418 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-delete-attribute-handles (after).

Metric Before After Change
🚀 Requests/sec 177.74 181.96 ⚪ +2.4%
⏱️ Latency P50 97.28 ms 95.86 ms ⚪ -1.5%
⏱️ Latency P95 230.45 ms 221.69 ms ⚪ -3.8%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 95.86 221.69 11,400 181.96 -8.76
Account 181.09 349.03 600 10.23 -50.54
TablesDB 93.45 174.79 6,200 101.45 -11.17
Storage 87.41 192.99 3,000 50.52 +0.58
Functions 132.89 266.73 1,600 27.67 -1.15

Top API waits (after)

API request Max wait (ms)
account.name.update 500.71
functions.delete 453.64
tablesdb.rows.create 447.97
account.prefs.update 447.14
tablesdb.rows.increment 431.92

@abnegate
abnegate merged commit e182a59 into main Oct 5, 2026
50 checks passed
abnegate added a commit that referenced this pull request Oct 5, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant