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

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

Closed
4 tasks done
hej2010 opened this issue Sep 22, 2023 · 11 comments · Fixed by #8765
Closed
4 tasks done

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

hej2010 opened this issue Sep 22, 2023 · 11 comments · Fixed by #8765
Labels
state:released Released as stable version state:released-alpha Released as alpha version state:released-beta Released as beta version type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@hej2010
Copy link
Contributor

hej2010 commented Sep 22, 2023

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

@parse-github-assistant
Copy link

parse-github-assistant bot commented Sep 22, 2023

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

@mtrezza mtrezza added the type:bug Impaired feature or lacking behavior that is likely assumed label Sep 22, 2023
@mtrezza
Copy link
Member

mtrezza commented Sep 22, 2023

Could you try the Parse Server versions in between 6.2 and 6.3, to we can pin down since when the issue was introduced? I assume it may be related to #8733, which has been released in 6.2.2.

@hej2010
Copy link
Contributor Author

hej2010 commented Sep 24, 2023

It works up to 6.2.1, but starting with 6.2.2 and up it has that issue.

@mtrezza
Copy link
Member

mtrezza commented Sep 24, 2023

Could you write a filing test for this in a PR?

cc @Moumouls

@hej2010
Copy link
Contributor Author

hej2010 commented Sep 26, 2023

PR opened :)

@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.4.0-alpha.5

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Oct 14, 2023
@Moumouls
Copy link
Member

thanks a lot @hej2010 !

@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.5.0-beta.1

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label Nov 16, 2023
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.5.0-alpha.1

@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.5.0

@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 7.0.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:released Released as stable version state:released-alpha Released as alpha version state:released-beta Released as beta version type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
4 participants