Skip to content

fix(events): check row and document actions against their own level - #14742

Merged
ChiragAgg5k merged 3 commits into
appwrite:mainfrom
callmegautam:fix-14653-upsert-event-validation
Oct 24, 2026
Merged

ChiragAgg5k merged 3 commits into
appwrite:mainfrom
callmegautam:fix-14653-upsert-event-validation

Conversation

@callmegautam

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes function and webhook subscriptions to row/document upsert events, which were rejected with 400 general_argument_invalid ("Event is not valid").

For a 7-part pattern such as tablesdb.*.tables.*.rows.*.upsert, Event::isValid() reads the action from $parts[6] but looked it up one level too high, in $events[$type][$subType] (the tables / collections level). create, update and delete passed only because that level has actions with the same names. upsert exists only under rows / documents, so every row or document upsert subscription was refused.

The validator now checks the action against $events[$type][$subType][$subSubType] when the pattern has a sub-sub resource. 3-part and 5-part patterns are unchanged.

Test Plan

  • Added unit assertions in tests/unit/Event/Validator/EventValidatorTest.php:
    • valid: tablesdb.*.tables.*.rows.*.upsert, tablesdb.books.tables.chapters.rows.*.upsert, databases.*.collections.*.documents.*.upsert, databases.books.tables.chapters.rows.prolog.upsert, documentsdb.*.collections.*.documents.*.upsert, vectorsdb.*.collections.*.documents.*.upsert
    • invalid: tablesdb.*.tables.*.upsert (upsert is not a table action), tablesdb.*.tables.*.rows.*.unknown
  • Without the fix the test fails at the first upsert assertion. With the fix:
    • vendor/bin/phpunit tests/unit/Event passes (46 tests, 413 assertions)
    • pint --test passes on both files
    • phpstan analyse src/Appwrite/Event/Validator/Event.php reports no errors

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 changes.)

@ghost

ghost commented Oct 21, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The new validation path preserves the parent-resource ID guard, and the added tests cover both malformed patterns and valid upsert subscriptions.

The event validator now checks row and document actions against their nested resource definitions, allowing valid upsert subscriptions while retaining existing action checks at shallower levels. Regression tests cover upsert patterns across database event types and ensure nested patterns with an empty parent resource ID remain invalid.

Latest changes: The follow-up consolidates parent- and nested-resource action validation while retaining the non-empty parent ID check, and adds regression cases for empty table IDs.

Verdict New comments Fixed Still open
💬 Commented 0 1 0

Note

@callmegautam does not have write access to this repository, so Hansi does not approve automatically. A maintainer can review and approve.

📂 Walkthrough · 2
File Change
src/Appwrite/Event/Validator/Event.php Selects action definitions from the matching parent or nested resource and continues rejecting empty parent resource IDs.
tests/unit/Event/Validator/EventValidatorTest.php Adds negative cases for row patterns with an empty table ID.
✅ Fixed since the last review · 1
  • Keep rejecting an empty parent resource ID · src/Appwrite/Event/Validator/Event.php:95

Merged main (d5c4d8a); no changes to this PR's code since 3f197db · 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 A · See the inline comments. Summary

Comment thread src/Appwrite/Event/Validator/Event.php Resolved

@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

@ChiragAgg5k
ChiragAgg5k merged commit 22a47c8 into appwrite:main Oct 24, 2026
118 of 120 checks passed
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: Function and webhook events reject tablesdb.*.tables.*.rows.*.upsert ("Event is not valid")

3 participants