Skip to content

fix(databases): use the database 8 relationship type in realtime relationship payloads - #14542

Merged
abnegate merged 1 commit into
mainfrom
fix-var-relationship
Oct 15, 2026
Merged

abnegate merged 1 commit into
mainfrom
fix-var-relationship

Conversation

@abnegate

Copy link
Copy Markdown
Member

What broke

main has been red since a10d3fd, the merge of #14349 (relationship attributes left out of create and transaction commit event payloads). That PR compares attribute types against Database::VAR_RELATIONSHIP. The locked utopia-php/database 8.1.4 no longer defines that constant: the query-lib migration (#11649) replaced the VAR_* constants with the Utopia\Query\Schema\ColumnType enum. The last green main is f50c5bd (run 38699067303).

Every main CI run after that has failed: a10d3fd, ca35312, 5204588, cdfd6a6 and d8c624f. On d8c624f (run 38712290555):

  • Checks: PHPStan reports classConstant.notFound three times, for Utopia\Database\Database::VAR_RELATIONSHIP at
    • Collections/Documents/Action.php:511 (triggerBulk, bulk create/update/upsert/delete events)
    • Collections/Documents/Create.php:494 (single create)
    • Transactions/Update.php:536 (transaction commit)
  • E2E: the Realtime, GraphQL, Usage, Webhooks, ProjectWebhooks, Databases and TablesDB jobs fail. The appwrite container logs, which are tail-limited, contain 334 Undefined constant Utopia\Database\Database::VAR_RELATIONSHIP fatals across those jobs (248 in GraphQL alone). The tests see these as 500s on document create, bulk writes and PATCH /databases/transactions/{id} commits. A commit 500 reports Transactions/Update.php line 536. Webhook deliveries for row creates go missing for the same reason.

Fix

Compare against ColumnType::Relationship->value. This is how the rest of the Databases module already checks for relationship attributes, for example Documents/Update.php, Bulk/Delete.php, Attribute/Increment.php, and Documents/Action.php:234 in the same class.

The comparison holds in every path that reaches it:

  • Appwrite's collection documents (create and bulk paths) hold attribute documents whose type is the string 'relationship'.
  • In the transaction path, getCollection() returns a Utopia\Database\Collection. Its constructor normalises typed Attribute objects, stored documents and raw arrays into documents whose type comes from Attribute::storedType(ColumnType::Relationship), which is 'relationship'. A local probe built a Collection from all three shapes and ran both filter idioms on it. Each one picked out exactly the relationship keys.

No other constants were removed. A token-based scan of src, app, bin, packages and tests checked every Utopia\* and Appwrite\* class constant reference. It found no other undefined constant; the scan does flag the three original references when run on the unfixed files. A full PHPStan run over the project is clean.

Verification

  • vendor/bin/phpstan analyse -c phpstan.neon (full project): [OK] No errors. On the unfixed files it reports the three classConstant.notFound errors above.
  • Pint (--test) on the changed files: passed.
  • composer refactor:check (Rector dry-run over tests/) and Rector on the changed files: no changes.
  • Unit tests for tests/unit/Event, tests/unit/Databases and tests/unit/Platform/Modules/Databases: 86 tests, all passing.
  • Not run locally: the E2E suite. Its own regression tests are RealtimeCustomClientTest::testCreateRelationshipPayloadAlignsWithUpdate and ::testTransactionCommitRelationshipPayloadAlignsWithUpdate from Omit relationship attributes from create and transaction commit event payloads #14349. Both go through the fixed lines, and they return 500 without this change.

Unblocks

The query-lib release-blocker PRs #14535, #14536, #14537 and #14538 inherit this red from main. They can go green once this merges.

🤖 Generated with Claude Code

…tionship payloads

#14349 filtered relationship attributes out of create and transaction
commit event payloads by comparing against Database::VAR_RELATIONSHIP.
utopia-php/database 8 removed the VAR_* constants in favour of the
ColumnType enum, so every document create, bulk event trigger and
transaction commit fataled with an undefined constant and returned 500,
and PHPStan reported three classConstant.notFound errors.

Compare against ColumnType::Relationship->value, the idiom the rest of
the module already uses. Stored _metadata attributes, Appwrite attribute
documents and the Collection returned by getCollection() all carry the
type as the string 'relationship' (Attribute::storedType), so the filter
matches in every path that reaches it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@luxor-code-review

luxor-code-review Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR replaces hardcoded relationship-type string comparisons with the ColumnType::Relationship enum value in three Databases files, keeping transactional document creates and transaction commit processing behaviorally identical. Review found no defects: the enum's value matches the legacy string, and all producers covering correctness, concurrency, API contract, and cross-file impact published empty candidate sets.

Files Change
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php Relationship-attribute filtering now uses the ColumnType::Relationship enum value instead of the legacy constant string.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php Same constant swap on the document create path so relationship handling matches the shared action filter.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php Transaction commit path applies the identical enum-based detection, keeping both entry points consistent.

Reviewed commit: abb2f10

@ghost

ghost commented Oct 15, 2026

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The enum comparison matches the stored relationship type and existing event tests cover the affected create and transaction paths.

Realtime relationship detection for bulk and single-document create payloads, and transaction commit payloads, now uses ColumnType::Relationship->value. This keeps relationship fields identified for sensitive-payload filtering with the current database/query type definitions.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 3
File Change
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php Uses the query enum value when finding relationship attributes for bulk events.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php Imports ColumnType and uses its relationship value for create events.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php Imports ColumnType and uses its relationship value for transaction commit events.

Reviewed abb2f10 · 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

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-var-relationship (after).

Metric Before After Change
🚀 Requests/sec 213.72 215.5 ⚪ +0.8%
⏱️ Latency P50 77.42 ms 79.21 ms ⚪ +2.3%
⏱️ Latency P95 201.58 ms 192.13 ms ⚪ -4.7%
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 79.21 192.13 13,680 215.5 -9.44
Account 165.55 295.94 720 12.18 -10.1
TablesDB 75.72 147.66 7,440 120.79 +5.72
Storage 74.12 160.68 3,600 59.67 -12.23
Functions 124.89 223.73 1,920 32.47 -28.89

Top API waits (after)

API request Max wait (ms)
account.name.update 440.64
account.prefs.update 396.77
functions.delete 376.76
functions.variables.create 355.87
functions.create 343.94

@abnegate
abnegate merged commit 2c72744 into main Oct 15, 2026
38 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Oct 21, 2026
6 tasks
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