fix: sorting by non-existing value throws INVALID_SERVER_ERROR on Postgres (#8157)

This commit is contained in:
dblythy
2022-09-18 04:41:45 +10:00
committed by GitHub
parent 73e1763a63
commit 3b775a1fb8
2 changed files with 13 additions and 0 deletions

View File

@@ -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) {

View File

@@ -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()