Skip to content

Context is undefined in Cloud code beforeFind for queries using include #8759

Description

@hej2010

New Issue Checklist

Issue Description

I updated from Parse 6.2.0 to 6.3.0 and it appears to have changed how queries with include(...) are made.
The req.context is empty in Parse.Cloud.beforeFind() when using a query with include().

For a query like:

const posts = await new Parse.Query("Post")
    .include("user") <- pointer to a _User
    ...
    .find({ context: {...}, sessionToken: ... });

in the old version the beforeFind was only called once and had the specified context object.

But in the latest (6.3.0) version the beforeFind is called twice, once for the query to Post (with the context object) and another time for the query to _User (with no context object and the query {"where":{"objectId":{"$in":[objectId1, objectId2, ... ]}}}).

I use the beforeFind to only allow queries made from the cloud code for certain classes (by using the find context), but for queries with include it is no longer possible to check if the query was made from cloud code or from a client SDK.

Steps to reproduce

Define beforeFind, like:

Parse.Cloud.beforeFind("Post", async req => {
    if (!req.master && !req.isGet) {
        if (!req.context) { throw "Empty") }
    }
});
Parse.Cloud.beforeFind(Parse.User, async req => {
    if (!req.master && !req.isGet) {
        if (!req.context) { throw "Empty") }
    }
});

and use a query like:

const posts = await new Parse.Query("Post")
    .include("user") <- pointer to a _User
    ...
    .find({ context: {...}, sessionToken: ... });

Actual Outcome

The context in beforeFind("Post", ...) is the context object defined in the query.
The context in beforeFind(Parse.User, ...) (or any class that is included in a query) is undefined/empty.

Expected Outcome

The context is defined in both beforeFind functions.

Environment

Server

  • Parse Server version: 6.3.0

Database

  • System (MongoDB or Postgres): MongoDB

Logs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    state:releasedReleased as stable versionstate:released-alphaReleased as alpha versionstate:released-betaReleased as beta versiontype:bugImpaired feature or lacking behavior that is likely assumed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions