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

directAccess + query.aggregate + dates no longer work #7748

Closed
4 tasks done
jonas-db opened this issue Dec 28, 2021 · 9 comments · Fixed by #8167
Closed
4 tasks done

directAccess + query.aggregate + dates no longer work #7748

jonas-db opened this issue Dec 28, 2021 · 9 comments · Fixed by #8167
Labels
state:released Released as stable version state:released-5.x.x Released as LTS 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

@jonas-db
Copy link

jonas-db commented Dec 28, 2021

New Issue Checklist

Issue Description

When you start the server with the option directAccess, the execution of a pipeline does not return results when you pass a Date instance to match.

Steps to reproduce

  1. The following test fails when directAccess is set to true and 'date': date
  2. The following test passes when directAccess is set to false and 'date': date
  3. The following test passes when directAccess is set to true or false and date : date.toISOString().

It remains unclear whether this behaviour was intended in previous versions (<5)

    it('fails', async () => {
        const registration = await Parse.User.signUp("jonas", "test", {});
        expect(registration.id).to.be.exist

        const user = await Parse.User.logIn("jonas", "test");
        expect(user.get('sessionToken')).to.be.exist
        expect(user.id).to.be.exist

        const TestObject = Parse.Object.extend('TestObject');

        const date = new Date()
        const testObject = await new TestObject({
            date: date,
        }).save({}, { useMasterKey : true });

        const match = {
            'date': { "$gte": date, "$lte": date } // Does not work when directAccess is true
            //'date': { "$gte": date.toISOString(), "$lte": date.toISOString()} // Works for both
        }
        
        console.log(match)

        const pipeline = [
            {
                "$match" : match
            }
        ]
        const query = new Parse.Query(TestObject);
        const result = await query.aggregate(pipeline).catch(e => e);
        console.log("results=",util.inspect(result, { showHidden: false, depth: null }))

        const query2 = new Parse.Query(TestObject);
        const result2 = await query2.equalTo('date', date).find().catch(e => e);
        console.log("results2=",util.inspect(result2, { showHidden: false, depth: null }))

        expect(result).to.be.lengthOf(1)
        expect(result2).to.be.lengthOf(1)
        expect(result[0].objectId).to.be.equal(result2[0].id)
    });

Actual Outcome

When (1)

results= []
results2= [
  ParseObjectSubclass {
    className: 'TestObject',
    _objCount: 9,
    id: 'jXEY7xFC3a'
  }
]

Expected Outcome

When (2) or (3)

results= [
  {
    date: { __type: 'Date', iso: '2021-12-28T13:51:11.961Z' },
    createdAt: '2021-12-28T13:51:11.962Z',
    updatedAt: '2021-12-28T13:51:11.962Z',
    objectId: 'xNLwllPXlu'
  }
]
results2= [
  ParseObjectSubclass {
    className: 'TestObject',
    _objCount: 9,
    id: 'xNLwllPXlu'
  }
]

Environment

Server

  • Parse Server version: ^5.0.0-beta.4
  • Operating system: macos
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): local

Database

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

Client

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

Logs

@parse-github-assistant
Copy link

parse-github-assistant bot commented Dec 28, 2021

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
Copy link
Member

mtrezza commented Dec 29, 2021

Could you open a PR with a simplified version of the test so we can reproduce this? Simplified meaning that it should only contain lines that are required to reproduce the issue. Instead of logging in a user you can run the query with masterkey.

Are you observing the issue also on 4.x or only 5.x versions?

@mtrezza mtrezza added type:bug Impaired feature or lacking behavior that is likely assumed severity:medium labels Dec 29, 2021
@mtrezza
Copy link
Member

mtrezza commented Sep 13, 2022

@jonas-db Do you have any update on this issue?

@dblythy
Copy link
Member

dblythy commented Sep 14, 2022

I was able to confirm this issue on a real Parse Server. The issue is that directAccess passes a Date object directly to the pipeline, and the server thinks it should be a string (as normally JSON.parse() can't convert dates) and attempts to convert the string to a date. The request payload is the same in both cases, however for directAccess, the pipeline object is an instanceof Date, whereas without it is a string. It results in the pipeline being converted to {}, resulting in no matches.

The fix is very simple.

I attempted to write a failing test for this on Parse Server using directAccess but was unable, as the pipeline date was always stringified in the test suite.

@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 5.3.0-alpha.24

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Sep 17, 2022
@parseplatformorg
Copy link
Contributor

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

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label Oct 29, 2022
@parseplatformorg
Copy link
Contributor

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

@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 5.4.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Nov 19, 2022
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 5.4.0

@parseplatformorg parseplatformorg added the state:released-5.x.x Released as LTS version label Nov 19, 2022
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-5.x.x Released as LTS 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