-
-
Notifications
You must be signed in to change notification settings - Fork 12
fix: check and complaint if @@index references fields fro m delegate base
#322
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
Conversation
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.
Pull Request Overview
This PR fixes issue #283 by adding validation to prevent @@index attributes from referencing fields inherited from delegate base models, extending the existing validation that was already in place for @@unique and @@id attributes.
- Extended the field inheritance validation to also check
@@indexattributes - Made error messages dynamic to reflect the actual attribute name being validated
- Added regression test to verify the fix
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/regression/test/issue-283.test.ts | Adds test case verifying that @@index correctly rejects fields inherited from polymorphic base models |
| packages/language/src/validators/attribute-application-validator.ts | Extends validation to include @@index and makes error messages dynamic to work across all three attribute types |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
WalkthroughThe pull request introduces validation to prevent inherited fields from polymorphic base models from being used in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes The changes are focused and straightforward: a validation rule addition with consistent pattern (dynamic error messages) and a targeted regression test. The logic is well-scoped to a specific constraint scenario with minimal branching or complexity. Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 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 |
|
Claude finished @ymc9's task —— View job Code Review Complete ✅Reviewing this PR that fixes issue #283 by adding validation for Review Tasks:
✅ Overall Assessment: LGTMThis is a clean, focused fix that properly extends existing validation logic to cover 📋 Code Quality & Best Practices✅ Excellent:
Code Quality Score: 9/10 🧪 Test Coverage✅ Good coverage:
Coverage Score: 8/10 🔒 Security✅ No security concerns: This is a validation enhancement that prevents potentially problematic schema definitions. No security implications. ⚡ Performance✅ No performance impact: The change reuses existing validation logic with no additional computational overhead. 🐛 Potential Issues & Suggestions✅ No issues found. The implementation correctly:
📝 Specific Code ReviewFile:
File:
🔍 Edge Cases ConsideredLooking at the validation logic in
🎯 RecommendationAPPROVE - This PR successfully fixes issue #283 with a minimal, well-tested change that follows existing code patterns perfectly. |
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 (3)
tests/regression/test/issue-283.test.ts (2)
4-5: Test structure is clear.The test suite properly references issue #283. The test name is functional, though a more descriptive name like
'prevents @@index from using inherited fields in polymorphic models'would better document the constraint being tested.
6-22: Consider expanding test coverage.The test correctly validates the new error message for the issue, which is a significant improvement over the cryptic "Could not resolve reference" error mentioned in issue #283. However, consider adding these test cases to the suite for more comprehensive coverage:
- Only inherited fields: Test
@@index([x])to ensure it also triggers the error- Only own fields: Test
@@index([y])to verify this valid case still works- Non-polymorphic inheritance: Test a base without
@@delegateto clarify the constraint is specific to polymorphic modelsAdditionally, the error message could be more specific to aid debugging:
`Field 'x' is inherited from polymorphic base model 'Base' and cannot be used in @@index`Would you like me to generate additional test cases to expand coverage?
packages/language/src/validators/attribute-application-validator.ts (1)
297-336: Consider renaming method to reflect broader scope.The method
_checkUniquenow validates three distinct attributes (@@id,@@index,@@unique), making its name misleading. Consider renaming to better reflect its broader purpose.Apply this diff to rename the method:
- private _checkUnique(attr: AttributeApplication, accept: ValidationAcceptor) { + private _checkFieldBasedAttribute(attr: AttributeApplication, accept: ValidationAcceptor) {
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/language/src/validators/attribute-application-validator.ts(3 hunks)tests/regression/test/issue-283.test.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
{packages,samples,tests}/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place packages only under
packages/,samples/, ortests/
Files:
tests/regression/test/issue-283.test.tspackages/language/src/validators/attribute-application-validator.ts
🧬 Code graph analysis (1)
packages/language/src/validators/attribute-application-validator.ts (1)
packages/sdk/src/schema/schema.ts (1)
AttributeApplication(39-42)
⏰ 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: build-test (20.x, sqlite)
- GitHub Check: claude-review
- GitHub Check: build-test (20.x, postgresql)
🔇 Additional comments (4)
tests/regression/test/issue-283.test.ts (1)
1-2: LGTM!The imports are appropriate for a regression test that validates error behavior.
packages/language/src/validators/attribute-application-validator.ts (3)
299-299: Good addition for dynamic error messaging.Introducing
attrNameto capture the attribute name dynamically improves error message specificity across@@id,@@index, and@@uniqueattributes.
308-308: LGTM! Dynamic error messages improve clarity.The use of
${attrName}in error messages at lines 308 and 326 provides more specific feedback to users, clearly indicating which attribute constraint (@@id,@@index, or@@unique) is being validated.Also applies to: 326-326
325-329: No issues found — validation is correct and well-tested.The code at lines 325-329 correctly implements an intentional restriction. Issue #283 specifically tests this scenario: a Base model with
@@delegate(type)where Sub extends Base and attempts to use inherited fieldxin@@index([x, y]). The expected error "Cannot use fields inherited from a polymorphic base model" confirms this is the intended behavior.Additionally, the language design allows models to extend only delegate models (not regular models), so inherited fields are inherently from polymorphic base models. Regression tests are already in place for both
@@indexand@@uniqueattributes.
|
Claude finished @ymc9's task —— View job Code Review Complete ✅Reviewing this PR that fixes issue #283 by adding validation for Review Tasks:
✅ Overall Assessment: LGTMThis is a clean, focused fix that properly extends existing validation logic to cover 📋 Code Quality & Best Practices✅ Excellent:
Code Quality Score: 9/10 🧪 Test Coverage✅ Good coverage:
Coverage Score: 8/10 🔒 Security✅ No security concerns: This is a validation enhancement that prevents potentially problematic schema definitions. No security implications. ⚡ Performance✅ No performance impact: The change reuses existing validation logic with no additional computational overhead. 🐛 Potential Issues & Suggestions✅ No issues found. The implementation correctly:
📝 Specific Code ReviewFile:
File:
🔍 Edge Cases ConsideredLooking at the validation logic in
🎯 RecommendationAPPROVE - This PR successfully fixes issue #283 with a minimal, well-tested change that follows existing code patterns perfectly. |
fixes #283
Summary by CodeRabbit
Bug Fixes