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

request.user is not up-to-date #1836

Closed
iForests opened this issue May 19, 2016 · 10 comments
Closed

request.user is not up-to-date #1836

iForests opened this issue May 19, 2016 · 10 comments

Comments

@iForests
Copy link

I have a simple Cloud Function:

Parse.Cloud.define('testQuery', function(request, response) {
    var user = request.user;
    response.success("user.get('data') = " + user.get('data'));
});

And a simple function call from Android SDK:

ParseCloud.callFunctionInBackground("testQuery", new HashMap<String, Object>(), new FunctionCallback<String>() {
    @Override
    public void done(String result, ParseException e) {
        if (e == null) {
            Log.d("testQuery", result);
        }
    }
});

Let's say the value "data" of my User object is "AAA". I call the function from Android SDK. Parse.com's server and self-hosted server both return user.get('data') = AAA.

Now I change the value of "data" to "BBB" from Dashboard, and call the function again. The results are different. Parse.com's server returns user.get('data') = BBB as expected, but the self-hosted server still returns user.get('data') = AAA.

Is it a correct behavior of the new Parse-Server or is it a bug? And if it's a correct behavior, how can I get the up-to-date data of request.user. Thanks.

@drew-gross
Copy link
Contributor

We have lots of passing test cases that cover these features. Can you post some code that reliably reproduces your issue? Ideally as a test case we can add to our test suite.

@iForests
Copy link
Author

I'm sure the code above reproduces this issue reliably. I've tested it many times, and the self-hosted server return the old value until I force quit the app and restart it.

@drew-gross
Copy link
Contributor

What version of Parse Server are you using? How are you updating the user? Are you sure everything is configured correctly? These things matter. For requests like these we usually ask for complete reproduction code from start to finish because it is quite common for someone to think they've found a bug, then when they try to make a complete test case they realize they misconfigured something somewhere.

I might have suspected that this is a caching issue, but our cache TTL is 5 seconds by default, and it doesn't sound like you are only seeing this issue for 5 seconds.

@iForests
Copy link
Author

  1. I'm using Parse Server 2.2.10 and Android SDK 1.13.0. Just ran npm update and restarted the server 10 min ago.
  2. I updated the user's data from the Dashboard on parse.com (https://www.parse.com/apps/xxx/collections#class/_User). I'm sure that I saved the new data correctly, since after I forced quit and restarted the app, I get the new data.

Please let me know if I can provide any useful information. Thanks.

@drew-gross
Copy link
Contributor

Does the error still happen if you use a self-hosted Parse Dashboard or an SDK to change the value? Does it still happen if you disable the cache or set the TTL to, say, 0 or 1 seconds?

@blacha this error looks a lot like a caching issue, any thoughts?

@iForests
Copy link
Author

iForests commented May 19, 2016

I tried modifying the value by REST API to both servers (parse.com and self-hosted), but the value I got from Android app didn't change. Here are the steps what I've done:

  • Force quit the app. Change the value to "Hello" from dashboard.
  • Open the app and click a button to call the Cloud Function. The result is "Hello" as expected.
  • Use the following REST API to change the value. I can confirm that the value changed successfully by checking the value in dashboard. Click the button to call the function again. The result should be "B", but I still get an "Hello".
(It's Parse.com's server.)

curl -X PUT \
  -H "X-Parse-Application-Id: xxx" \
  -H "X-Parse-Master-Key: xxx" \
  -H "Content-Type: application/json" \
  -d '{"data":"B"}' \
  https://api.parse.com/1/users/4gXtXgcGYY
  • Use the following REST API to change the value. I can confirm that the value changed successfully by checking the value in dashboard. Click the button to call the function again. The result should be "C", but again, I get an "Hello".
(It's self-hosted server.)

curl -X PUT \
  -H "X-Parse-Application-Id: xxx" \
  -H "X-Parse-Master-Key: xxx" \
  -H "Content-Type: application/json" \
  -d '{"data":"C"}' \
  http://10.20.30.40:1337/parse/users/4gXtXgcGYY

I can't find out the way in the documentation to disable the cache or set TTL. Can you give me a link or show me how to do that? Thank you!

@drew-gross
Copy link
Contributor

I'm trying this myself and not seeing the issue. Can you please tell me how to reproduce this issue starting from nothing? No Parse.com apps, no self hosted server, etc. I suspect there is some problem with how you've configured your database, or your Parse Server, or your SDK. The dashboard uses the same Javascript SDK as the open source one, so if the dashboard is working, then I'm sure the SDK will work too.

Try enabled verbose logging with VERBOSE=1 env var for your Parse Server and making sure the requests and responses are consistent with what you are describing.

@iForests
Copy link
Author

iForests commented May 19, 2016

Actually, I'm not sure that I can reproduce this issue from nothing, since it's a migrated app. I'll give it a try later and report back, but before that, is the following code & results providing any useful information?

Let's say the data is "A" at the beginning. I uninstall and reinstall the app, and call the function. The result is:

verbose: {
  "response": {
    "result": "s1: undefined s2: A s3: A"
  }
}

Now I change the value from dashboard to "B", and call the function again, the result becomes:

verbose: {
  "response": {
    "result": "s1: A s2: B s3: B"
  }
}

Here is the code:

Parse.Cloud.define('testQuery', function(request, response) {
    var user = request.user;
    var s1 = 's1: ' + user.get('data');

    user.fetch({useMasterKey: true}).then(function(newUser) {
        var s2 = ' s2: ' + user.get('data');
        var s3 = ' s3: ' + newUser.get('data');

        response.success(s1 + s2 + s3);
    });
});

Thanks.

@drew-gross
Copy link
Contributor

OK, I think I see the cause. It seems like the issue is that we don't fetch the user from the database when calling a cloud function, we use the one provided in the request. I'll double check the behavior of Parse.com and then submit a PR to match the issue in Parse Server.

@drew-gross
Copy link
Contributor

Fixed by #1844

drew-gross added a commit that referenced this issue May 22, 2016
…ixes #1836) (#1844)

* Cache users by objectID, and clear cache when updated via master key

* Go back to caching by session token. Clear out cache by querying _Session when user is modified with Master Key (ew, hopefully that can be improved later)

* Fix issue with user updates from different sessions causing stale reads

* Tests aren't transpiled...

* Still not transpiled
JeremyPlease pushed a commit to JeremyPlease/parse-server that referenced this issue May 24, 2016
…ixes parse-community#1836) (parse-community#1844)

* Cache users by objectID, and clear cache when updated via master key

* Go back to caching by session token. Clear out cache by querying _Session when user is modified with Master Key (ew, hopefully that can be improved later)

* Fix issue with user updates from different sessions causing stale reads

* Tests aren't transpiled...

* Still not transpiled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants