Conversation
📝 WalkthroughWalkthroughTwo new InvalidArgumentException catch blocks were added to updateAttribute in app/controllers/api/databases.php (two locations), mapping that exception to GENERAL_ARGUMENT_INVALID while retaining existing TypeException handling (ATTRIBUTE_TYPE_INVALID). Both endpoints now set the event label to a generic "update" and include the target documentId in the event payload. tests/e2e/Services/Databases/DatabasesBase.php adds assertions that PATCH count increment/decrement calls with value: 0 return HTTP 400; the decrement test block calls the increment endpoint while expecting 400. No public API or function signatures were changed. Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
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: 1
🔭 Outside diff range comments (1)
app/controllers/api/databases.php (1)
281-287: Bug: Incorrect parentheses break attribute type/filter validationBoth conditionals are currently evaluating the wrong expressions due to misplaced parentheses. They likely always evaluate truthy/falsy incorrectly and can reject valid updates or mask invalid ones.
Fix with:
- if ($attribute->getAttribute(('type') !== $type)) { + if ($attribute->getAttribute('type') !== $type) { throw new Exception(Exception::ATTRIBUTE_TYPE_INVALID); } - if ($attribute->getAttribute('type') === Database::VAR_STRING && $attribute->getAttribute(('filter') !== $filter)) { + if ($attribute->getAttribute('type') === Database::VAR_STRING && $attribute->getAttribute('filter') !== $filter) { throw new Exception(Exception::ATTRIBUTE_TYPE_INVALID); }Consider adding/adjusting tests that hit updateAttribute() with mismatched type and filter to prevent regressions.
🧹 Nitpick comments (3)
app/controllers/api/databases.php (2)
4554-4557: Catching InvalidArgumentException and mapping to GENERAL_ARGUMENT_INVALID is correct. Consider preserving the exception chain.Good addition; it standardizes 0-value increments as a client error (400). Minor nit: preserve the original exception as "previous" to aid debugging and logs.
Apply this diff:
- } catch (InvalidArgumentException $e) { - throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $e->getMessage()); + } catch (InvalidArgumentException $e) { + throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $e->getMessage(), previous: $e); }
4633-4636: Same improvement for decrement: keep the exception chain.Symmetric handling is good. Keep the previous exception to aid diagnostics.
Apply this diff:
- } catch (InvalidArgumentException $e) { - throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $e->getMessage()); + } catch (InvalidArgumentException $e) { + throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $e->getMessage(), previous: $e); }tests/e2e/Services/Databases/DatabasesBase.php (1)
5572-5581: Zero-increment test is good; consider asserting mapped error type (GENERAL_ARGUMENT_INVALID).To make the test more robust against regression in exception mapping, assert the error type as well.
$inc3 = $this->client->call(Client::METHOD_PATCH, "/databases/$databaseId/collections/$collectionId/documents/$docId/count/increment", array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ 'value' => 0 ]); $this->assertEquals(400, $inc3['headers']['status-code']); + $this->assertEquals(Exception::GENERAL_ARGUMENT_INVALID, $inc3['body']['type']);
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
composer.lockis excluded by!**/*.lock
📒 Files selected for processing (2)
app/controllers/api/databases.php(2 hunks)tests/e2e/Services/Databases/DatabasesBase.php(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
app/controllers/api/databases.php (1)
src/Appwrite/Extend/Exception.php (1)
Exception(7-408)
tests/e2e/Services/Databases/DatabasesBase.php (2)
tests/e2e/Client.php (1)
Client(8-328)src/Appwrite/Event/Event.php (1)
getProject(151-154)
🪛 PHPMD (2.15.0)
tests/e2e/Services/Databases/DatabasesBase.php
5704-5704: Avoid unused local variables such as '$docId'. (Unused Code Rules)
(UnusedLocalVariable)
⏰ 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: Setup & Build Appwrite Image
- GitHub Check: Setup & Build Appwrite Image
- GitHub Check: scan
🔇 Additional comments (1)
app/controllers/api/databases.php (1)
4529-4547: Confirm DB adapter exception types for increase/decreaseDocumentAttributeI couldn't find the implementations of increaseDocumentAttribute/decreaseDocumentAttribute in this repo (search returned only call sites) — I cannot confirm they throw only InvalidArgumentException for value=0. Please verify the DB adapter (likely external) and ensure controllers catch/map any additional unchecked exceptions.
Files/call sites to check and/or update if adapter throws other exceptions:
- app/controllers/api/databases.php — increase block (≈ lines 4539–4556) and decrease block (≈ lines 4618–4636)
- src/Appwrite/Platform/Workers/Webhooks.php:150
- src/Appwrite/Platform/Workers/Deletes.php:660
- src/Appwrite/Deletes/Targets.php:45
- app/controllers/api/messaging.php:2538 and 2844
- app/controllers/api/teams.php:631, 1284, 1387
Action requested:
- Confirm which exception classes the DB implementation throws for invalid values (e.g., value=0).
- If it can throw other unchecked exceptions, map them to API Exceptions (or add explicit catches) similar to existing mappings (ConflictException, NotFoundException, LimitException, TypeException, InvalidArgumentException).
✨ 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