-
Notifications
You must be signed in to change notification settings - Fork 55
Validate order #728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate order #728
Conversation
WalkthroughAdds validation that rejects ordering by nested attributes when the top-level segment exists in the schema, causing an immediate validation failure and message "Cannot order by nested attribute: {attribute}". Adds an e2e test asserting this behavior for both order-by and cursor usage with a relationship attribute. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Client
participant O as Order::isValid
participant S as Schema
C->>O: Validate order attribute (e.g., "author.name")
O->>O: Detect dot in attribute
O->>S: Check top-level segment exists
alt Top-level exists and attribute is nested
O-->>C: Error "Cannot order by nested attribute: {attribute}"\nreturn false
else No dot or top-level not found
O->>O: Proceed with standard validation
O-->>C: Validation result (success/failure)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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). (1)
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/Database/Validator/Query/Order.php (1)
40-44: Consider including the full original attribute path in the error message.The error message currently uses the truncated top-level segment (e.g., "author") rather than the full dot-path the user provided (e.g., "author.name"). While the validation logic is correct, including the full original attribute would make debugging easier for users.
You could store the original attribute before exploding and use it in the error message:
+ $originalAttribute = $attribute; $attribute = \explode('.', $attribute)[0]; if (isset($this->schema[$attribute])) { - $this->message = 'Cannot order by nested attribute: ' . $attribute; + $this->message = 'Cannot order by nested attribute: ' . $originalAttribute; return false; }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/Database/Validator/Query/Order.php(1 hunks)tests/e2e/Adapter/Scopes/RelationshipTests.php(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-03T02:04:17.803Z
Learnt from: abnegate
PR: utopia-php/database#721
File: tests/e2e/Adapter/Scopes/DocumentTests.php:6418-6439
Timestamp: 2025-10-03T02:04:17.803Z
Learning: In tests/e2e/Adapter/Scopes/DocumentTests::testSchemalessDocumentInvalidInteralAttributeValidation (PHP), when the adapter reports getSupportForAttributes() === false (schemaless), the test should not expect exceptions from createDocuments for “invalid” internal attributes; remove try/catch and ensure the test passes without exceptions, keeping at least one assertion.
Applied to files:
tests/e2e/Adapter/Scopes/RelationshipTests.php
🧬 Code graph analysis (1)
tests/e2e/Adapter/Scopes/RelationshipTests.php (3)
src/Database/Database.php (2)
Database(37-8134)find(6695-6826)src/Database/Adapter/SQL.php (1)
find(2334-2513)src/Database/Query.php (4)
Query(8-1116)equal(435-438)orderAsc(602-605)cursorAfter(645-648)
🔇 Additional comments (4)
tests/e2e/Adapter/Scopes/RelationshipTests.php (4)
4416-4432: LGTM!The test setup correctly creates the necessary collections, attributes, and relationships to validate ordering behavior with nested relationship attributes.
4434-4471: LGTM!Test data is properly structured with appropriate authors and posts to exercise the validation logic.
4473-4483: LGTM!The test correctly verifies that ordering by a nested relationship attribute throws a validation error with the expected message. The use of
$caughtflag ensures the exception is actually thrown.
4485-4500: LGTM!The cursor test correctly verifies that combining a cursor with an invalid nested order attribute triggers the same validation error. The test properly distinguishes between creating a valid cursor and using it with an invalid order attribute.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Summary by CodeRabbit
New Features
Bug Fixes
Tests