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

User.get('username') undefined in afterSave Cloud function #836

Closed
davidruisinger opened this issue Mar 4, 2016 · 10 comments · Fixed by #992
Closed

User.get('username') undefined in afterSave Cloud function #836

davidruisinger opened this issue Mar 4, 2016 · 10 comments · Fixed by #992

Comments

@davidruisinger
Copy link

Environment Setup

Version 2.1.4

Steps to reproduce

Cloud function:

Parse.Cloud.afterSave('_User', function(request, response) {
  Parse.Cloud.useMasterKey();
  console.log(request.object.get('username'));
}

Logs/Trace

When signing up a new user this returns undefined

@sdf611097
Copy link
Contributor

2.1.4 afterSave for _User does not fetch full data.
But this issue seems have been resolved with latest code.

@davidruisinger
Copy link
Author

Still undefined in 2.1.5

@flovilmart
Copy link
Contributor

Check with 2.1.6 that's just out?

@sdf611097
Copy link
Contributor

2.1.6 is not work, I'm finding my code is base on which commit.
I can get username when after save user on my env.

@sdf611097
Copy link
Contributor

my base is bd89338
It not up-to-date, but it's work. Sorry

@sdf611097
Copy link
Contributor

in
RestWrite.prototype.runAfterTrigger

add blow line, it will work
updatedObject._finishFetch(this.data);

I'm not sure why _finishFetch is gone

@flovilmart
Copy link
Contributor

_finishFetch has been replaced by updatedObject.set(Parse._decode(undefined, this.data));

Not sure why?

@nlutsenko ?

@sdf611097
Copy link
Contributor

seems updatedObject.set(Parse._decode(undefined, this.data)) not get the full data of user

the data before
triggers.maybeRunTrigger(triggers.Types.afterSave, this.auth, updatedObject, originalObject, this.config.applicationId);

updatedObject { createdAt: '2016-03-12T03:26:43.661Z',
sessionToken: 'r:69b9aa23572345a69f21725d5dfb2b29',
updatedAt: '2016-03-12T03:26:43.661Z',
objectId: 'TvaH7oXI9p' }
originalObject undefined

print by
console.log('updatedObject',updatedObject.toJSON());
console.log('originalObject',originalObject);

_finishFetch will get username but npm test failed

miscellaneous afterSave flattens custom operations
Message:
Expected IncrementOp({ _amount: 1 }) to equal 1.
Stack:
Error: Expected IncrementOp({ _amount: 1 }) to equal 1.
at ParseAPI.spec.js:756:36
at triggers.js:161:5
at new Promise (/Users/ChunTingLin/parse-server/node_modules/babel-polyfill/node_modules/core-js/modules/es6.promise.js:197:7)
at Object.maybeRunTrigger (triggers.js:152:10)

Hope this info is useful

@flovilmart
Copy link
Contributor

The fetch occurs earlier, for some reason, all the data is properly set before going into the trigger, but for some reason, the get() is not properly performed.

@flovilmart
Copy link
Contributor

I found the error. Proposing a fix soon

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

Successfully merging a pull request may close this issue.

3 participants