fix: normalize order case in MongoDB adapter#848
Conversation
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Greptile SummaryThis PR adds
Confidence Score: 3/5The fix partially resolves the reported issue but introduces a silent correctness regression for CURSOR_BEFORE paginated queries with lowercase sort orders. A P1 logic bug remains: after the fix, a CURSOR_BEFORE query with a lowercase order value will silently return results sorted in the wrong direction instead of throwing an exception. This is a present, reproducible defect on the changed code path and should be addressed before merging. src/Database/Adapter/Mongo.php — specifically the cursor-direction reversal block around line 2077 and the Important Files Changed
|
Summary
getOrder()does a strictmatchagainstDatabase::ORDER_ASC('ASC') andDatabase::ORDER_DESC('DESC')'asc'/'desc', it falls through to the default case and throws"Unknown sort order:asc"strtoupper()to normalize the input before matchingRoot cause
The Appwrite backend's index creation WhiteList validator accepts lowercase orders (non-strict mode lowercases for comparison), but stores the original lowercase value. When the database worker processes the index, it passes the stored lowercase value to
getOrder()which rejects it.Document sorting is unaffected because
Query::groupByType()maps order queries to uppercaseDatabase::ORDER_ASC/Database::ORDER_DESCconstants — a completely separate code path that never touches the SDK'sOrderByenum values.Test plan
asc/desc)