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. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughMongoDB errors caused by invalid query hints are mapped to ChangesInvalid Hint Error Handling
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 6 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (6 passed)
✨ 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. 🔧 Biome (2.5.5)src/Adapters/Storage/Mongo/MongoStorageAdapter.jsFile contains syntax errors that prevent linting: Line 3: 'import type' are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.; Line 178: classes can only implement interfaces in TypeScript files; Line 180: return types can only be used in TypeScript files; Line 181: return types can only be used in TypeScript files; Line 182: return types can only be used in TypeScript files; Line 183: return types can only be used in TypeScript files; Line 184: return types can only be used in TypeScript files; Line 185: return types can only be used in TypeScript files; Line 185: expected a semicolon to end the class property, but found none; Line 185: Expected an identifier, a string literal, a number literal, a private field name, or a computed name but instead found '; Line 185: type parameters are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.; Line 185: Expected a class parameters but instead found ';'.; Line 186: ret ... [truncated 15553 characters] ... Illegal return statement outside of a function; Line 1286: Expected a semicolon or an implicit semicolon after a statement, but found none; Line 1287: Illegal return statement outside of a function; Line 1297: Expected a semicolon or an implicit semicolon after a statement, but found none; Line 1300: Illegal return statement outside of a function; Line 1303: expected 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
INVALID_QUERYerror instead of a generic internal server error.Tests