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

Updating an existing user that is online throws an error #78

Open
lukef opened this issue Jun 4, 2020 · 3 comments
Open

Updating an existing user that is online throws an error #78

lukef opened this issue Jun 4, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@lukef
Copy link

lukef commented Jun 4, 2020

If you first grab a user record like so:

filter := map[string]interface{}{
    "id": "<user id>",
}
users, usersErr := streamClient.QueryUsers(&stream.QueryOption{
    Filter: filter,
    Limit:  1,
})

Then modify the user and attempt to save it, like ..

streamUser.Image = "<photo url>"
_, streamUpdateErr := streamClient.UpdateUser(streamUser)

It will fail with the following error:

chat-client: HTTP POST https://chat-us-east-1.stream-io-api.com/users?api_key=<secret> status 400 Bad Request: {\"code\":4,\"message\":\"UpdateUsers failed with error: \\\"users[<userid>].online is a reserved field\\\"\",\"exception_fields\":{\"users[<userid>].online\":\"users[<userid>].online is a reserved field\"}

It seems like if that is reserved, it should be omitted?

@ferhatelmas
Copy link
Contributor

@lukef even if error is clear, SDK definitely should help more here.

@ferhatelmas ferhatelmas added the enhancement New feature or request label Jun 5, 2020
@lukef
Copy link
Author

lukef commented Jun 6, 2020

@ferhatelmas absolutely. The issue, primarily, is that there is no way to strip out anything "reserved" or to know what is actually reserved if you're just trying to update an existing record after fetching it. i.e.:

  • Get User
  • Update user model
  • Re-Save user

It's actually impossible to do this use case btw. It will fail every time (hence this ticket).

In the above scenario, it will contain the entire user record and any attributes / values that may/may not be reserved.

It might be useful to have an update struct to differentiate between a user and what the API requires. e.g.:

type UserUpdateOptions struct {
  // allowed values here
}

This way you can create a set of "safe" options that can be updated.

@ferhatelmas
Copy link
Contributor

ferhatelmas commented Jun 8, 2020

@lukef It's clear, not convenient in this flow.

Your suggestion sounds reasonable at first but we already have a partial update and it's in that direction so if a client knows what to (un)set, it's the preferred way to accomplish that.

In the example flow, anything reserved should be filtered automatically or to save some work from SDKs, server can ignore them.

/cc @thesyncim what do you think about ignoring in server side ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants