Skip to content

Cannot update custom value in User class #256

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

Closed
Tridie2000 opened this issue Aug 23, 2019 · 12 comments
Closed

Cannot update custom value in User class #256

Tridie2000 opened this issue Aug 23, 2019 · 12 comments

Comments

@Tridie2000
Copy link

Tridie2000 commented Aug 23, 2019

My User class has a custom property (points). I'm trying to update this property. According to a print statement I added to the code it seems to work except I don't see any change on the server side.

ParseUser user = await ParseUser.currentUser() as ParseUser;
if (user != null) {
   ParseUser incrementUser = ParseUser.forQuery()..getObject(user.objectId);
   incrementUser.set('points', (user.get('points') + 1));
   await incrementUser.save();
   print('save: $incrementUser');
}
@Tridie2000
Copy link
Author

Tridie2000 commented Aug 25, 2019

I also tried this piece of code and the response is successful but the data doesn't update on the server. What is going on here?

ParseUser user = await ParseUser.currentUser() as ParseUser;
 if (user != null) {
   user.set('points', user.get('points') + 1);
   ParseResponse response = await user.save();
   if (response.success) {
     print('ok');
   } else {
     print(response.error);
   }
   print('save: $user');
}

@danibjor
Copy link

Check user.objectId. Is that set? Or is it null?

@Tridie2000
Copy link
Author

The user objectId is not null.

@mdc555
Copy link

mdc555 commented Oct 9, 2019

Any update on this??
Same here. I've tried several ways but it's not updating. But curiously, it was working fine and I didn't any change to my code....

@mdc555
Copy link

mdc555 commented Oct 9, 2019

The User doesn't get updated when it's logged in....

@mdc555
Copy link

mdc555 commented Oct 12, 2019

I've finally managed to get this working. I had to move that logic to a Cloud Code passing masterKey: true and everything is fine but I couldn't get it working straight from my app. I didn't get any error on my logs. Supposedly everything was OK but the user never updated.
I tried to logout and login back the user and at that point it worked but whenever I started my app that update never happened. A bit strange but now solved using Cloud Code.

@jbcaveman
Copy link

Parse always generates tight ACLs on the User class, so you cannot modify a user in the client SDK unless that user is the authenticated currentUser. That said, you should always increment values on the server side rather than client side to avoid stale data issues and other conflicts. To save objects with tight ACLs server-side, you need to be sure to specify using the master key, like:
incrementUser.save(null, { useMasterKey: true });

@jbcaveman
Copy link

If you haven't yet, this is a must-read for anyone using Parse Server: https://docs.parseplatform.org/js/guide/#security

@mdc555
Copy link

mdc555 commented Oct 12, 2019

I have ACLs on my User class. The user I was trying to update was the currentUser already authenticated. As I said, I didn't get any error. It just didn't update the currentUser.
It only worked when the user have just logged in but it didn't worked when the user opens the app and have an "active session"

@fischerscode
Copy link
Contributor

Is this still a problem?

fischerscode added a commit to fischerscode/Parse-SDK-Flutter that referenced this issue Apr 29, 2020

Verified

This commit was signed with the committer’s verified signature.
tongyuantongyu Yuan Tong
This should be a fix for:
parse-community#364
and
parse-community#256
phillwiggins pushed a commit that referenced this issue Apr 29, 2020

Verified

This commit was signed with the committer’s verified signature.
tongyuantongyu Yuan Tong
* added subclass handler

* integraded subclass handler

* added constructor for QueryBuilder using registered SubClasses

* subclass handler optimizations

* Convenience changes

* Convenience change

* sembast CoreStore on macos

* Fix: ParseUser updated on server but not locally

This should be a fix for:
#364
and
#256

* Update README.md

* Update README.md
@kristiehuang
Copy link

Not sure if this was resolved, but getting same exact problem

I have ACLs on my User class. The user I was trying to update was the currentUser already authenticated. As I said, I didn't get any error. It just didn't update the currentUser.
It only worked when the user have just logged in but it didn't worked when the user opens the app and have an "active session"

@fischerscode
Copy link
Contributor

@kristiehuang
Some changes have been made in 1.0.27 and I think this has been solved.
Are you using version 1.0.27 (not yet released to pub.dev) or an older version?

phillwiggins added a commit that referenced this issue Aug 28, 2020
* Release 1.0.27 - Create base branch

* Fix for #347 (include in LiveList) (#348)

* LiveList: reload included objects

First implementation

* Key was wrong on order change

* include sub-includes

* reuse loaded pointers

* Deleted stuff

* LiveList autoupdate included sub-objects (#349)

* LiveList: reload included objects

First implementation

* Key was wrong on order change

* include sub-includes

* reuse loaded pointers

* Deleted stuff

* Adding listening on included objects to LiveList

* Updated readme for ParseLiveList

* Update parse_live_list.dart

* LiveList: sync subObjects after reconnect (#352)

* Sync subObjects after reconnect

* Update README.md

* Update README.md (#353)

* ISSUE-351: Replaced isTypeOfException with Exception (#355)

Great work! Thank you

* RegisterSubClass and smaler changes (#368)

* added subclass handler

* integraded subclass handler

* added constructor for QueryBuilder using registered SubClasses

* subclass handler optimizations

* Convenience changes

* Convenience change

* sembast CoreStore on macos

* Fix: ParseUser updated on server but not locally

This should be a fix for:
#364
and
#256

* Update README.md

* Update README.md

* Update README.md (#367)

* Save installationId when new installation created. Send installationId when User login (#375)

* ParseLiveElement (#376)

* First implementation for ParseLiveElement

* ParseLiveElement further implementation

* Update parse_live_list.dart

* ParseLiveElement working

* News methods for ParseQuery -  whereMatchesKeyInQuery and whereDoesNotMatchKeyInQuery (#379)

* Add method whereMatchesKeyInQuery

Add method whereMatchesKeyInQuery

* Update parse_query.dart

* Fix whereMatchesKeyInQuery / whereDoesNotMatchKeyInQuery

* Update README.md

* Update README.md

* Update README.md

* Add google login helper (#387)

- Update README to show how to get google login attributes for parse

* Update parse_response_builder.dart (#390)

* [web] Check web before Platform.isX (#392)

Platform.isX is unsupported in web

* Make web compatible calls for locale and skip PackageInfo (#395)

* Make web compatible calls for locale and skip PackageInfo

* Also get country code for web locale

* Add description of early web support

* Added ParseFile check to _canBeSerialized() (#396)

* Update README.md (#397)

Fix Parse Server parameter name

* ParseLiveList: first implementation of lazyLoading (#407)

Setting lazyLoading=false should disable lazyLoading.

* Update parse_live_list.dart (#406)

In theory this should not make any difference. In practise sometimes an error gets thrown:
The following NoSuchMethodError was thrown while finalizing the widget tree:
The method 'dispose' was called on null.
Receiver: null
Tried calling: dispose()

* File Support for web (#409)

* created files and started implementation

* add different filetypes to sdk

* Update README.md

* add an other file example to README (#410)

* added file example to README

* Update README.md

* Web file upload: set content type to "text/plain" incase neighter name nor url is set (#411)

This breaks the extension at the uploaded file, but otherwise the upload would fail with a server error.

* LiveQuery reconnecting intervals (#414)

* parseFileConstructor was missing at Parse.initialize

* add liveListRetryIntervals to Parse.initialize

* replace kIsWeb with its definition (#415)

Using less libaries is always good.

* release/1.0.27 update dependencies

* Release/1.0.27 (#427)

* forgetLocalSession before login / signUP / loginAnonymous #426

* forgetLocalSession before login / signUP / loginAnonymous #426

* Release 1.0.27 - Pre-release process
- Update dependencies

* Release 1.0.27 - Pre-release process
- Static analysis fixes

Co-authored-by: Maximilian Fischer <[email protected]>
Co-authored-by: Michal Baran <[email protected]>
Co-authored-by: Maximilian Fischer <[email protected]>
Co-authored-by: Phani Rithvij <[email protected]>
Co-authored-by: Danaru <[email protected]>
Co-authored-by: Rodrigo de Souza Marques <[email protected]>
Co-authored-by: vreamer <[email protected]>
Co-authored-by: Dmytro Karpovych <[email protected]>
Co-authored-by: Nils Strelow <[email protected]>
Co-authored-by: hyperrecursive <[email protected]>
fischerscode added a commit to fischerscode/Parse-SDK-Flutter that referenced this issue Sep 5, 2020
* added subclass handler

* integraded subclass handler

* added constructor for QueryBuilder using registered SubClasses

* subclass handler optimizations

* Convenience changes

* Convenience change

* sembast CoreStore on macos

* Fix: ParseUser updated on server but not locally

This should be a fix for:
parse-community#364
and
parse-community#256

* Update README.md

* Update README.md
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

8 participants