fix: Return INVALID_QUERY for invalid MongoDB hints#10497
Conversation
|
I will reformat the title to use the proper commit message syntax. |
|
🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review. Tip
Note Please respond to review comments from AI agents just like you would to comments from a human reviewer. Let the reviewer resolve their own comments, unless they have reviewed and accepted your commit, or agreed with your explanation for why the feedback was incorrect. Caution Pull requests must be written using an AI agent with human supervision. Pull requests written entirely by a human will likely be rejected, because of lower code quality, higher review effort and the higher risk of introducing bugs. Please note that AI review comments on this pull request alone do not satisfy this requirement. Our CI and AI review are safeguards, not development tools. If many issues are flagged, rethink your development approach. Invest more effort in planning and design rather than using review cycles to fix low-quality code. |
|
Need an answer fast? Review this PR in Change Stack to ask focused questions about the PR or a changed range. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughClassifies MongoDB errors caused by invalid query hints and maps them to Parse.Error.INVALID_QUERY in the Mongo storage adapter; adds a test verifying a query using a missing hint returns INVALID_QUERY and includes "hint" in the message. ChangesInvalid Hint Error Handling
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 OpenGrep (1.22.0)OpenGrep fatal error (exit code 2): [00.12][ERROR]: Error: exception Unix_error: No such file or directory stat spec/ParseQuery.hint.spec.js 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 |
|
Thanks for the feedback. This PR is ready for review from my side. I used AI assistance to help inspect the code path and prepare the fix, but I reviewed the changes myself and ran the targeted regression test locally. Validation run:
CodeRabbit did not raise any actionable comments, so I will wait for the maintainer review. |
| expect(explain.queryPlanner.winningPlan.inputStage.inputStage.indexName).toBe('_id_'); | ||
| }); | ||
|
|
||
| it_only_mongodb_version('<5.1 || >=6')('query find with invalid hint returns invalid query error', async () => { |
There was a problem hiding this comment.
Why is this gated on mongodb versions?
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alpha #10497 +/- ##
==========================================
+ Coverage 92.60% 92.61% +0.01%
==========================================
Files 193 193
Lines 16919 16927 +8
Branches 234 234
==========================================
+ Hits 15667 15677 +10
+ Misses 1229 1227 -2
Partials 23 23 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
4870f4c to
86e05e4
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
spec/ParseQuery.hint.spec.js (1)
169-170: ⚡ Quick winReduce backend-message coupling in this assertion.
The
toContain('index')check is brittle because MongoDB/driver wording can vary by version while still correctly mapping toINVALID_QUERY. Keep the behavior contract assertion on error code (and optionallyhint) and drop the strictindextoken requirement.Suggested test adjustment
- expect(error.message.toLowerCase()).toContain('index'); + // Avoid coupling to MongoDB version-specific phrasing. + expect(error.message.toLowerCase()).toContain('hint');🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@spec/ParseQuery.hint.spec.js` around lines 169 - 170, Remove the brittle "index" substring assertion in the test; update the assertion block in spec/ParseQuery.hint.spec.js so it asserts the error.code equals 'INVALID_QUERY' (and may still assert the error.message contains 'hint' if desired) and drop the expect(error.message.toLowerCase()).toContain('index') check to avoid coupling to driver wording.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@spec/ParseQuery.hint.spec.js`:
- Around line 169-170: Remove the brittle "index" substring assertion in the
test; update the assertion block in spec/ParseQuery.hint.spec.js so it asserts
the error.code equals 'INVALID_QUERY' (and may still assert the error.message
contains 'hint' if desired) and drop the
expect(error.message.toLowerCase()).toContain('index') check to avoid coupling
to driver wording.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d0ec53c4-622a-44b3-91e6-d2fcff173be1
📒 Files selected for processing (2)
spec/ParseQuery.hint.spec.jssrc/Adapters/Storage/Mongo/MongoStorageAdapter.js
🚧 Files skipped from review as they are similar to previous changes (1)
- src/Adapters/Storage/Mongo/MongoStorageAdapter.js
86e05e4 to
64a8c0b
Compare
|
Thanks for the feedback. I’ve updated the test to keep it focused on the actual behaviour we want to protect. Changes made:
I also reran the targeted test locally:
|
Summary
Map invalid MongoDB
hinterrors to a clean ParseINVALID_QUERYresponse instead of surfacing them as internal server errors.Changes
MongoStorageAdapter.handleError()Parse.Error.INVALID_QUERYspec/ParseQuery.hint.spec.jsTesting
npm test -- spec/ParseQuery.hint.spec.jsFixes #8288
Summary by CodeRabbit
Bug Fixes
Tests