diff --git a/spec/ParseQuery.spec.js b/spec/ParseQuery.spec.js index b7c3fe02d7..f0a3640529 100644 --- a/spec/ParseQuery.spec.js +++ b/spec/ParseQuery.spec.js @@ -5375,6 +5375,22 @@ describe('Parse.Query testing', () => { expect(result.executionStats).not.toBeUndefined(); }); + it_only_db('mongo')('does not run afterFind on explain results', async () => { + let afterFindCalled = false; + Parse.Cloud.afterFind('AfterFindExplain', () => { + afterFindCalled = true; + return []; // empty return would drop the explain plan if the trigger ran + }); + const obj = new Parse.Object('AfterFindExplain'); + await obj.save(); + const query = new Parse.Query('AfterFindExplain'); + query.equalTo('objectId', obj.id); + query.explain(); + const result = await query.find({ useMasterKey: true }); + expect(result.executionStats).not.toBeUndefined(); // plan passed through untouched + expect(afterFindCalled).toBe(false); // afterFind skipped for explain + }); + it('should query with distinct within eachBatch and direct access enabled', async () => { await reconfigureServer({ directAccess: true, diff --git a/src/RestQuery.js b/src/RestQuery.js index 51a65ce17d..7fccef47d8 100644 --- a/src/RestQuery.js +++ b/src/RestQuery.js @@ -1121,8 +1121,8 @@ _UnsafeRestQuery.prototype.runAfterFindTrigger = function () { if (!hasAfterFindHook) { return Promise.resolve(); } - // Skip Aggregate and Distinct Queries - if (this.findOptions.pipeline || this.findOptions.distinct) { + // Skip Aggregate, Distinct and Explain Queries + if (this.findOptions.pipeline || this.findOptions.distinct || this.findOptions.explain) { return Promise.resolve(); }