Skip to content

After Save User is not returning fields that I need #8387

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

Open
matheusfrozzi opened this issue Jan 14, 2023 · 6 comments
Open

After Save User is not returning fields that I need #8387

matheusfrozzi opened this issue Jan 14, 2023 · 6 comments
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@matheusfrozzi
Copy link

New Issue Checklist

Issue Description

After Save User is not returning fields that I need
the result will not come with this field, even if you put manually on AfterSave.
But if you put manually on AfterSave a property that doesn't exist on the database, it will return.
The login endpoint returns all the properties right.

Steps to reproduce

Create a property on Parse.User and Save a new Parse User filling this property.

Actual Outcome

Not returning properties like 'fullName'

Expected Outcome

Return properties that I need

Environment

Parse server Version 5.4.0 with MongoDB 5

Server

  • Parse Server version: 5.40
  • Operating system: Linux Ubuntu
  • Local or remote host: Google Cloud

Database

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

Logs

@parse-github-assistant
Copy link

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 Jan 15, 2023

Could you add a complete step by step example code to demo the issue? With only the minimal code that's needed please.

@matheusfrozzi
Copy link
Author

matheusfrozzi commented Jan 15, 2023

Hey @mtrezza of course!

POST - /users

{
"fullName": "Matheus",
"username": "[email protected]",
"password": password",
}

Expected return:

{
    "fullName": "Matheus",
    "username": "[email protected]",
    "createdAt": "2023-01-15T12:31:14.501Z",
    "email": "[email protected]",
    "sessionToken": "***",
    "updatedAt": "2023-01-15T12:31:14.501Z",
    "objectId": "kU4vahS0x9"
}

Actual return:

{
    "username": "[email protected]",
    "createdAt": "2023-01-15T12:33:08.364Z",
    "sessionToken": "*",
    "objectId": "wG2oPSTbMr",
    "email": "[email protected]",
    "password": {
        "__op": "Delete"
    }
}

Code:

Parse.Cloud.afterSave(Parse.User, async (request) => {
    let user = request.object;
 
    // if I add here user.set('isPremium', true) it returns on the API
    return user
})

@matheusfrozzi
Copy link
Author

It's weird
If I do this it work.

    var fullName = user.get("fullName") + "  _"
    console.log(fullName)
    user.unset("fullName")
    user.set("fullName", fullName)

but if i put the var without change
var fullName = user.get("fullName")

It doesn't. ahah weird

@dblythy
Copy link
Member

dblythy commented Jan 15, 2023

Related:

#7839
#8159

We updated the save response so it would only be keys that are updated. But in the case of pendingOps, perhaps it could make sense to return the latest database value instead of the op.

We also updated afterSave triggers so that a response could be returned to the client different to the one in the database.

You can override the save response though by returning JSON, such as:

Parse.Cloud.afterSave(Parse.User, async (request) => {
    let user = request.object;
    return user._toFullJSON();
})

@matheusfrozzi
Copy link
Author

Hey @dblythy thanks for adding the related links.

But I'm changing the fullName and it isn't returning, and updatedAt was created too and isn't returning.
Doesn;t look like it is working.

And yes, this op is a problem for serialization, I opened other issue that I can't remove from the return the ops and It broke my serialization. :/

@mtrezza mtrezza added the type:bug Impaired feature or lacking behavior that is likely assumed label Jan 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

3 participants