Skip to content

fix(events): generate the attribute event before the action event - #13527

Merged
HarshMN2345 merged 1 commit into
mainfrom
fix/event-name-drops-attribute
Sep 8, 2026
Merged

HarshMN2345 merged 1 commit into
mainfrom
fix/event-name-drops-attribute

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Event::generateEvents() built its pattern list with the attribute-qualified pattern after the plain action pattern for top-level resources, so for users.[userId].update.name the generated list started with the less specific event:

users.<id>.update | users.*.update | users.<id>.update.name | users.*.update.name | users.<id> | users.*

Consumers that have to report a single name read events[0] — the functions worker publishes it as x-appwrite-event / APPWRITE_FUNCTION_EVENT (Workers/Functions.php:190), and Realtime::toTailMetadata() derives its metadata from it. A function triggered by a name change therefore saw APPWRITE_FUNCTION_EVENT=users.<id>.update, with the .name silently dropped. Same for .email, .phone, .password, .status, .prefs, .labels, .mfa, .verification and teams.*.update.prefs.

Sub-resource patterns already emitted the most specific event first (users.<id>.sessions.<id>.delete is events[0]), and testWildcardDeduplicationPreservesDeliveryOrder already pins that invariant for the database family. This only fixes the one branch that broke it: the attribute pattern moves into the else branch, ahead of the action pattern.

users.<id>.update.name | users.*.update.name | users.<id>.update | users.*.update | users.<id> | users.*

That trailing if ($attribute) also applied to sub-resource patterns, so a membership status update was emitting teams.<id>.update.status and teams.*.update.status on top of the real events. Neither is in app/config/events.php, and Appwrite\Event\Validator\Event rejects them, so no webhook or function could ever have subscribed to them — they are now gone (16 events → 14).

Webhooks are unaffected: they already send the full list in X-Appwrite-Webhook-Events.

Test Plan

New regression test EventTest::testGenerateEventsOrder pins the full ordering for the reported pattern and asserts the sub-resource attribute case.

Before (on main):

FAIL order users.[userId].update.name
  got: users.torsten.update | users.*.update | users.torsten.update.name | users.*.update.name | users.torsten | users.*
FAIL no spurious parent attribute event

After:

docker compose exec appwrite test tests/unit/Event/
OK (14 tests, 281 assertions)

Existing expectations are unchanged — event counts (4 / 6 / 10 / 42), the mirror-event tests, and testWildcardDeduplicationPreservesDeliveryOrder all still pass, as does the full unit suite (1164 tests).

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs? — no API metadata changed.

`generateEvents()` appended the attribute-qualified pattern after the plain
action pattern for top-level resources, so `users.[userId].update.name`
generated `users.<id>.update` first. Consumers that report a single name read
`events[0]`, so a function triggered by a name change received
`APPWRITE_FUNCTION_EVENT=users.<id>.update` with the attribute dropped.

Sub-resource patterns already emitted the most specific event first; move the
attribute pattern into the same position for top-level resources so `events[0]`
is always the concrete event that happened. This also stops the block emitting
`teams.<id>.update.status` alongside a membership status update -- that event is
not in the events config and the event validator rejects it, so nothing can
subscribe to it.
@HarshMN2345
HarshMN2345 force-pushed the fix/event-name-drops-attribute branch from 55ccaa2 to 58c2928 Compare September 8, 2026 10:33
@greptile-apps

greptile-apps Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR corrects event generation ordering so top-level attribute-qualified events are emitted before their broader action events and prevents nested-resource attributes from producing invalid parent aliases.

  • Functions and realtime consumers that use the first generated event now receive the complete attribute-qualified name.
  • Broader action and resource patterns remain available for subscription matching.
  • Regression coverage verifies the exact top-level order and the nested membership-status behavior.

Confidence Score: 5/5

The PR appears safe to merge; the new ordering matches first-event consumer semantics without removing valid subscription patterns.

The implementation preserves concrete and wildcard delivery patterns while making the complete event name first, and the only removed nested alias is not part of the configured event contract.

Important Files Changed

Filename Overview
src/Appwrite/Event/Event.php Reorders top-level attribute events ahead of action events and limits attribute aliases to the resource level to which they belong.
tests/unit/Event/EventTest.php Adds focused regression coverage for complete event ordering and suppression of the invalid membership parent alias.

Reviews (1): Last reviewed commit: "fix(events): generate the attribute even..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/event-name-drops-attribute (after).

Metric Before After Change
🚀 Requests/sec 255.55 260.87 ⚪ +2.1%
⏱️ Latency P50 68.07 ms 66.76 ms ⚪ -1.9%
⏱️ Latency P95 161.52 ms 156.65 ms ⚪ -3%
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 66.76 156.65 16,074 260.87 -4.87
Account 134.12 246.52 846 14.03 -8.77
TablesDB 64.78 113.7 8,742 143.61 -7.27
Storage 61.24 127.57 4,230 71.88 -10.67
Functions 103.03 187.83 2,256 39.03 -2.97

Top API waits (after)

API request Max wait (ms)
functions.variables.update 392.31
account.name.update 370.12
account.get 299.64
account.prefs.update 289.68
functions.variables.delete 285.6

@HarshMN2345
HarshMN2345 merged commit 2ccafc7 into main Sep 8, 2026
46 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Sep 10, 2026
2 of 4 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.

🐛 Bug Report: event name for users.*.update.*.name is incorrect

2 participants