Skip to content

Commit

Permalink
fix: sorting by non-existing value throws INVALID_SERVER_ERROR on P…
Browse files Browse the repository at this point in the history
  • Loading branch information
dblythy authored Sep 17, 2022
1 parent 73e1763 commit 3b775a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions spec/ParseQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,16 @@ describe('Parse.Query testing', () => {
});
});

it('order by non-existing string', async () => {
const strings = ['a', 'b', 'c', 'd'];
const makeBoxedNumber = function (num, i) {
return new BoxedNumber({ number: num, string: strings[i] });
};
await Parse.Object.saveAll([3, 1, 3, 2].map(makeBoxedNumber));
const results = await new Parse.Query(BoxedNumber).ascending('foo').find();
expect(results.length).toBe(4);
});

it('order by descending number then ascending string', function (done) {
const strings = ['a', 'b', 'c', 'd'];
const makeBoxedNumber = function (num, i) {
Expand Down
3 changes: 3 additions & 0 deletions src/Controllers/DatabaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,9 @@ class DatabaseController {
`Invalid field name: ${fieldName}.`
);
}
if (!schema.fields[fieldName.split('.')[0]] && fieldName !== 'score') {
delete sort[fieldName];
}
});
return (isMaster
? Promise.resolve()
Expand Down

0 comments on commit 3b775a1

Please sign in to comment.