Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 10 commits into from
Sep 17, 2022
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]]) {
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
delete sort[fieldName];
}
});
return (isMaster
? Promise.resolve()
Expand Down