Tableid and Collectionid in increment and decrement routes#10952
Tableid and Collectionid in increment and decrement routes#10952
Conversation
📝 WalkthroughWalkthroughThis PR adds metadata attribution to increment and decrement operation responses. After successfully incrementing or decrementing a document attribute, the operations now set an additional field on the returned document containing the associated collection ID (for Collections/Documents) or table ID (for TablesDB). The implementation adds this attribute-setting logic to the post-success handlers in the Increment and Decrement classes. Corresponding test files are updated to verify that these new fields are present in the response payloads with correct values. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Security Scan Results for PRDocker Image Scan Results
Source Code Scan Results🎉 No vulnerabilities found! |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php (1)
172-181: Verify transaction-staging response uses the same$collectionId/$tableIdkey as the non-transaction response (and consider centralizing).The new
'$' . $this->getCollectionsEventsContext() . 'Id'attribute (Line 180) looks correct for the normal path, but thetransactionIdearly-return path builds$mockDocumentwith'$' . $groupId(Line 159-165). Please confirmgetGroupId()resolves to the same key (collectionIdvstableId) so staged vs non-staged responses don’t diverge. Also, this attribute-setting is duplicated in Decrement—consider a small helper to set it in one place.tests/e2e/Services/Databases/Legacy/DatabasesBase.php (2)
6115-6122: Add an explicit key-presence assertion for clearer failures (increment response).
If'$collectionId'is missing, PHP array access can produce noisy notices and the failure message is less actionable; asserting presence first makes the test output cleaner.$this->assertEquals(200, $inc['headers']['status-code']); $this->assertEquals(6, $inc['body']['count']); - $this->assertEquals($collectionId, $inc['body']['$collectionId']); + $this->assertArrayHasKey('$collectionId', $inc['body']); + $this->assertEquals($collectionId, $inc['body']['$collectionId']);
6226-6234: Add an explicit key-presence assertion for clearer failures (decrement response).
Same rationale as increment: validate the response shape before asserting equality.$this->assertEquals(200, $dec['headers']['status-code']); $this->assertEquals(9, $dec['body']['count']); - $this->assertEquals($collectionId, $dec['body']['$collectionId']); + $this->assertArrayHasKey('$collectionId', $dec['body']); + $this->assertEquals($collectionId, $dec['body']['$collectionId']);tests/e2e/Services/Databases/TablesDB/DatabasesBase.php (1)
7874-7877: Good coverage: validates$tableIdis echoed in decrement response.
Optional: also assert$tableIdon$inc2/$dec2to cover the non-default value paths.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php(1 hunks)src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php(1 hunks)tests/e2e/Services/Databases/Legacy/DatabasesBase.php(2 hunks)tests/e2e/Services/Databases/TablesDB/DatabasesBase.php(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: ItzNotABug
Repo: appwrite/appwrite PR: 9693
File: src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Update.php:57-59
Timestamp: 2025-06-19T09:20:03.312Z
Learning: In table-related endpoints (such as `src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Update.php`), parameter descriptions should use "table" and "row" terminology instead of "collection" and "document" for clarity and consistency.
🧬 Code graph analysis (2)
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php (3)
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php (1)
getCollectionsEventsContext(223-226)src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php (1)
getCollectionsEventsContext(203-206)src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php (1)
getCollectionsEventsContext(151-154)
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php (3)
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php (1)
getCollectionsEventsContext(223-226)src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php (1)
getCollectionsEventsContext(203-206)src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php (1)
getCollectionsEventsContext(151-154)
⏰ 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). (19)
- GitHub Check: E2E Service Test (Sites)
- GitHub Check: E2E Service Test (Locale)
- GitHub Check: E2E Service Test (Databases/Legacy)
- GitHub Check: E2E Service Test (Console)
- GitHub Check: E2E Service Test (Health)
- GitHub Check: E2E Service Test (Migrations)
- GitHub Check: E2E Service Test (GraphQL)
- GitHub Check: E2E Service Test (Teams)
- GitHub Check: E2E Service Test (Users)
- GitHub Check: E2E Service Test (Proxy)
- GitHub Check: E2E Service Test (Storage)
- GitHub Check: E2E Service Test (Databases/TablesDB)
- GitHub Check: E2E Service Test (Functions)
- GitHub Check: E2E Service Test (Avatars)
- GitHub Check: E2E Service Test (Realtime)
- GitHub Check: E2E Service Test (Site Screenshots)
- GitHub Check: E2E Service Test (Dev Keys)
- GitHub Check: E2E General Test
- GitHub Check: Unit Test
🔇 Additional comments (2)
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php (1)
172-181: LGTM—mirrors Increment, but double-check staged vs non-staged response key consistency.Setting
'$' . $this->getCollectionsEventsContext() . 'Id'(Line 180) is consistent with the desired behavior (collection vs table context). Same note as Increment: please confirm thetransactionIdearly-return path’s'$' . $groupIdkey matches this, so clients get the same field name in both modes.tests/e2e/Services/Databases/TablesDB/DatabasesBase.php (1)
7761-7764: Good coverage: validates$tableIdis echoed in increment response.
This aligns the test with the intended TablesDB metadata behavior.
✨ Benchmark results
⚡ Benchmark Comparison
|
What does this PR do?
(Provide a description of what this PR does and why it's needed.)
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
Checklist