Skip to content

Commit 3b775a1

Browse files
authored
fix: sorting by non-existing value throws INVALID_SERVER_ERROR on Postgres (#8157)
1 parent 73e1763 commit 3b775a1

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Diff for: spec/ParseQuery.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,16 @@ describe('Parse.Query testing', () => {
17151715
});
17161716
});
17171717

1718+
it('order by non-existing string', async () => {
1719+
const strings = ['a', 'b', 'c', 'd'];
1720+
const makeBoxedNumber = function (num, i) {
1721+
return new BoxedNumber({ number: num, string: strings[i] });
1722+
};
1723+
await Parse.Object.saveAll([3, 1, 3, 2].map(makeBoxedNumber));
1724+
const results = await new Parse.Query(BoxedNumber).ascending('foo').find();
1725+
expect(results.length).toBe(4);
1726+
});
1727+
17181728
it('order by descending number then ascending string', function (done) {
17191729
const strings = ['a', 'b', 'c', 'd'];
17201730
const makeBoxedNumber = function (num, i) {

Diff for: src/Controllers/DatabaseController.js

+3
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,9 @@ class DatabaseController {
12071207
`Invalid field name: ${fieldName}.`
12081208
);
12091209
}
1210+
if (!schema.fields[fieldName.split('.')[0]] && fieldName !== 'score') {
1211+
delete sort[fieldName];
1212+
}
12101213
});
12111214
return (isMaster
12121215
? Promise.resolve()

0 commit comments

Comments
 (0)