Skip to content

object.relation(..) throws "Invalid key '...'" when beforeFind() trigger change the query #7269

Open

Description

@sadortun

New Issue Checklist

Issue Description

Hi !

I have a beforeFind trigger that add a few restrictions on a child type, when executing parent.query().find() the server throw a Invalid key "$relatedTo"

Steps to reproduce

I have a Parent with a relation to a Child

Then:

// /cloud/index.js
  Parse.Cloud.beforeFind("Child", (req) => {
      const a = new Parse.Query("Child")
      const b = new Parse.Query("Child")

      a.equalTo('field', 'abcd')
      b.doesNotExist('field')

      return Parse.Query.and(req.query, Parse.Query.or(a, b)  )
})   

On the client

// client
const parent = new Parent()

await parent.relation('childs').query().find()

Actual Outcome

Error in mounted hook (Promise/async): "ParseError: 105 Invalid key name: $relatedTo"

Expected Outcome

An happy relation! 👪

Failing Test Case / Pull Request

It seems that reduceRelationKeys only checks for a Top level $or, and in my case, the top level operator is $and

This seems like it 'fixes' the issue :

  reduceRelationKeys(className, query, queryOptions) {
//    if (query['$or']) {
//      return Promise.all(query['$or'].map(aQuery => {
//        return this.reduceRelationKeys(className, aQuery, queryOptions);
//      }));
//    }
    for(const op of ['$or', '$and' , '$not']) {
      if (query[op]) {
        return Promise.all(query[op].map(aQuery => {
          return this.reduceRelationKeys(className, aQuery, queryOptions);
        }));
      }
    }
// ....
  • 🤩 I submitted a PR with a fix and a test case.
  • 🧐 I submitted a PR with a failing test case.

Environment

Server

  • Parse Server version: 4.5.0
  • Operating system: windows
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): local

Database

  • System (MongoDB or Postgres): mongo
  • Database version: 4.4?
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): local

Client

  • SDK (iOS, Android, JavaScript, PHP, Unity, etc): js
  • SDK version: 3.1.0

Logs

Activity

  1. davimacedo commented on Mar 15, 2021

    @davimacedo
    Member

    Thanks for the PR and investigation. Would you be willed to send a PR with the fix and a regression test case?

  2. sadortun commented on Mar 15, 2021

    @sadortun
    ContributorAuthor

    @davimacedo It may take a few days, but Yeah sure! If you confirm that the proposed solution above will not break everything :) I'm just smashing the keyboard until something works 🙈 😅

  3. davimacedo commented on Mar 15, 2021

    @davimacedo
    Member

    Thanks @sadortun . If all tests continue passing, it will probably not break anything. It is important to also add a new regression test case covering the problem you are trying to fix and maybe other tests to check potential problems you may think about.

  4. sadortun commented on Mar 16, 2021

    @sadortun
    ContributorAuthor

    @davimacedo @dplewis off topic question :) would it be possible that you add some information about the release cycles in the readme ? It would be really nice to have at least a patch release every month

  5. mtrezza commented on Mar 16, 2021

    @mtrezza
    Member

    @sadortun Parse Server currently does not have release cycles, but it is something we are looking into, see this discussion.

  6. sadortun commented on Mar 20, 2021

    @sadortun
    ContributorAuthor

    Hey @davimacedo should I iterate only over and, or, not or on all the special QueryKeys?

  7. davimacedo commented on Mar 22, 2021

    @davimacedo
    Member

    I believe only over and, or, not

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions