fix: add missing upsert event by abnegate · Pull Request #10317 · appwrite/appwrite · GitHub
Skip to content

fix: add missing upsert event - #10317

Merged
stnguyen90 merged 1 commit into
1.7.xfrom
fix-missing-upsert-event
Aug 14, 2025
Merged

stnguyen90 merged 1 commit into
1.7.xfrom
fix-missing-upsert-event

Conversation

@abnegate

@abnegate abnegate commented Aug 14, 2025 •

Copy link
Copy Markdown
Member

What does this PR do?

Add the upsert event because it's triggered by databases.upsertDocument().

In addition, this is important because this config is used as validation for webhooks and functions as part of event validation.

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Screenshots may also be helpful.)

Related PRs and Issues

  • (Related PR or issue)

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?

@coderabbitai

coderabbitai Bot commented Aug 14, 2025 •

Copy link
Copy Markdown
Contributor

@github-actions

Copy link
Copy Markdown

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
binutils 2.42-r0 CVE-2025-0840 HIGH
git 2.45.3-r0 CVE-2025-48384 HIGH
git 2.45.3-r0 CVE-2025-48385 HIGH
git-init-template 2.45.3-r0 CVE-2025-48384 HIGH
git-init-template 2.45.3-r0 CVE-2025-48385 HIGH
icu 74.2-r0 CVE-2025-5222 HIGH
icu-data-en 74.2-r0 CVE-2025-5222 HIGH
icu-dev 74.2-r0 CVE-2025-5222 HIGH
icu-libs 74.2-r0 CVE-2025-5222 HIGH
libexpat 2.6.4-r0 CVE-2024-8176 HIGH
libxml2 2.12.7-r0 CVE-2024-56171 HIGH
libxml2 2.12.7-r0 CVE-2025-24928 HIGH
libxml2 2.12.7-r0 CVE-2025-27113 HIGH
libxml2 2.12.7-r0 CVE-2025-32414 HIGH
libxml2 2.12.7-r0 CVE-2025-32415 HIGH
pyc 3.12.9-r0 CVE-2024-12718 HIGH
pyc 3.12.9-r0 CVE-2025-4138 HIGH
pyc 3.12.9-r0 CVE-2025-4330 HIGH
pyc 3.12.9-r0 CVE-2025-4517 HIGH
python3 3.12.9-r0 CVE-2024-12718 HIGH
python3 3.12.9-r0 CVE-2025-4138 HIGH
python3 3.12.9-r0 CVE-2025-4330 HIGH
python3 3.12.9-r0 CVE-2025-4517 HIGH
python3-pyc 3.12.9-r0 CVE-2024-12718 HIGH
python3-pyc 3.12.9-r0 CVE-2025-4138 HIGH
python3-pyc 3.12.9-r0 CVE-2025-4330 HIGH
python3-pyc 3.12.9-r0 CVE-2025-4517 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2024-12718 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2025-4138 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2025-4330 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2025-4517 HIGH
sqlite-libs 3.45.3-r1 CVE-2025-29087 HIGH
xz 5.6.2-r0 CVE-2025-31115 HIGH
xz-libs 5.6.2-r0 CVE-2025-31115 HIGH
golang.org/x/crypto v0.31.0 CVE-2025-22869 HIGH
golang.org/x/oauth2 v0.24.0 CVE-2025-22868 HIGH
stdlib 1.22.10 CVE-2025-47907 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
app/config/events.php (3)

112-117: Optional: keep key order stable to minimize churn

Unless there’s a strong reason to reorder, consider appending the new key without moving existing ones. This keeps diffs smaller and stays closer to existing conventions across this file.

Apply this diff to place 'upsert' after 'delete' while keeping semantics unchanged:

-                'upsert' => [
-                    '$description' => 'This event triggers when a document is upserted.',
-                ],
-                'delete' => [
-                    '$description' => 'This event triggers when a document is deleted.'
-                ],
+                'delete' => [
+                    '$description' => 'This event triggers when a document is deleted.'
+                ],
+                'upsert' => [
+                    '$description' => 'This event triggers when a document is upserted.',
+                ],

113-113: Nit: clarify wording for broader audiences

“Upserted” is correct, but some readers may not know the term. Small wording tweak improves clarity.

-                    '$description' => 'This event triggers when a document is upserted.',
+                    '$description' => 'This event triggers when a document is created or updated via an upsert operation.',

112-117: Verify 'upsert' event is actually emitted — route labels found, but no explicit emitter discovered

Quick summary: I searched the repo. The new config entry exists, and the databases controller declares event labels for upsert, and tests reference upsert flows — but I did not find explicit event-emission calls matching the "documents.*.upsert" pattern. Please confirm whether your framework emits events from the route/controller labels (->label('event', ...)) or whether an explicit emit needs to be added to the upsert code paths.

Files/locations to check:

  • app/config/events.php — new 'upsert' entry (lines ~112–117)
  • app/controllers/api/databases.php
    • ~4239: route for "Upsert document" with ->label('event', 'databases.[databaseId].collections.[collectionId].documents.[documentId].upsert') and ->label('audits.event', 'document.upsert')
    • ~4761: route for "Upsert documents" with ->label('audits.event', 'documents.upsert')
  • tests/e2e/Services/Databases/DatabasesCustomServerTest.php — multiple upsert-related tests
  • tests/e2e/Services/Databases/DatabasesBase.php — collection fixtures referencing upsert collections

Config snippet (unchanged):

                'upsert' => [
                    '$description' => 'This event triggers when a document is upserted.',
                ],
                'delete' => [
                    '$description' => 'This event triggers when a document is deleted.'
                ],

Requested action:

  • Confirm where event emission occurs (framework-level label→emit mechanism or explicit emit).
  • If no emitter exists for upsert, add emission(s) in the upsert code paths (single and bulk) and update/add tests.

I can help add the emit calls and tests once you confirm the desired emission mechanism.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a3ea1f and 6043cc2.

📒 Files selected for processing (1)
  • app/config/events.php (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-06-25T06:25:45.054Z
Learnt from: ItzNotABug
PR: appwrite/appwrite#9693
File: src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Delete.php:40-40
Timestamp: 2025-06-25T06:25:45.054Z
Learning: In Appwrite's database module, the event label for deleting a table index intentionally uses 'update' (e.g., 'databases.[databaseId].tables.[tableId].indexes.[indexId].update') instead of 'delete', to match legacy behavior as seen in previous controller implementations.

Applied to files:

  • app/config/events.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Benchmark
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

  • Requests per second: 981
  • Requests with 200 status code: 176,577
  • P99 latency: 0.186128301

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 981 982
200 176,577 176,720
P99 0.186128301 0.19536182

@stnguyen90
stnguyen90 self-requested a review August 14, 2025 14:22
@stnguyen90 stnguyen90 moved this to Code Review in 1.7 Release Aug 14, 2025
@stnguyen90 stnguyen90 changed the title Add upsert event fix: add missing upsert event Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants