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: Parse.Query.distinct fails due to invalid aggregate stage 'hint' #9295

Merged
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions spec/ParseQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

const Parse = require('parse/node');
const request = require('../lib/request');
const ParseServerRESTController = require('../lib/ParseServerRESTController').ParseServerRESTController;
const ParseServer = require('../lib/ParseServer').default;

const masterKeyHeaders = {
'X-Parse-Application-Id': 'test',
Expand Down Expand Up @@ -5275,4 +5277,33 @@ describe('Parse.Query testing', () => {
// Validate
expect(result.executionStats).not.toBeUndefined();
});

it('should query with distinct within eachBatch and direct access enabled', async () => {
await reconfigureServer({
directAccess: true,
});

Parse.CoreManager.setRESTController(
ParseServerRESTController(Parse.applicationId, ParseServer.promiseRouter({ appId: Parse.applicationId }))
);
mtrezza marked this conversation as resolved.
Show resolved Hide resolved

const user = new Parse.User();
user.set('username', 'foo');
user.set('password', 'bar');
await user.save();

const score = new Parse.Object('Score');
score.set('player', user);
score.set('score', 1);
await score.save();

await new Parse.Query('_User')
.equalTo('objectId', user.id)
.eachBatch(async ([user]) => {
const score = await new Parse.Query('Score')
.equalTo('player', user)
.distinct('score', { useMasterKey: true });
expect(score).toEqual([1]);
}, { useMasterKey: true });
});
});
26 changes: 13 additions & 13 deletions src/Routers/AggregateRouter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ClassesRouter from './ClassesRouter';
import rest from '../rest';
import * as middleware from '../middlewares';
import Parse from 'parse/node';
import * as middleware from '../middlewares';
import rest from '../rest';
import ClassesRouter from './ClassesRouter';
import UsersRouter from './UsersRouter';

export class AggregateRouter extends ClassesRouter {
Expand All @@ -11,20 +11,20 @@
if (body.distinct) {
options.distinct = String(body.distinct);
}
if (body.hint) {
options.hint = body.hint;
if (Object.prototype.hasOwnProperty.call(body, 'hint')) {
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
if (body.hint) options.hint = body.hint;

Check failure on line 15 in src/Routers/AggregateRouter.js

View workflow job for this annotation

GitHub Actions / Lint

Expected { after 'if' condition
delete body.hint;
}
if (body.explain) {
options.explain = body.explain;
if (Object.prototype.hasOwnProperty.call(body, 'explain')) {
if (body.explain) options.explain = body.explain;

Check failure on line 19 in src/Routers/AggregateRouter.js

View workflow job for this annotation

GitHub Actions / Lint

Expected { after 'if' condition
delete body.explain;
}
if (body.comment) {
options.comment = body.comment;
if (Object.prototype.hasOwnProperty.call(body, 'comment')) {
if (body.comment) options.comment = body.comment;

Check failure on line 23 in src/Routers/AggregateRouter.js

View workflow job for this annotation

GitHub Actions / Lint

Expected { after 'if' condition

Check warning on line 23 in src/Routers/AggregateRouter.js

View check run for this annotation

Codecov / codecov/patch

src/Routers/AggregateRouter.js#L23

Added line #L23 was not covered by tests
delete body.comment;
}
if (body.readPreference) {
options.readPreference = body.readPreference;
if (Object.prototype.hasOwnProperty.call(body, 'readPreference')) {
if (body.readPreference) options.readPreference = body.readPreference;

Check failure on line 27 in src/Routers/AggregateRouter.js

View workflow job for this annotation

GitHub Actions / Lint

Expected { after 'if' condition
delete body.readPreference;
}
options.pipeline = AggregateRouter.getPipeline(body);
Expand Down Expand Up @@ -52,7 +52,7 @@
}

/* Builds a pipeline from the body. Originally the body could be passed as a single object,
* and now we support many options
* and now we support many options.
*
* Array
*
Expand All @@ -71,7 +71,7 @@
*
* body: {
* pipeline: {
* group: { objectId: '$name' },
* $group: { objectId: '$name' },
* }
* }
*
Expand Down
Loading