Skip to content

Added object class check to current user controller's cache #964

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
wants to merge 2 commits into from
Closed

Added object class check to current user controller's cache #964

wants to merge 2 commits into from

Conversation

Vortec4800
Copy link

This is a fix for the issue identified in #963.

If the _currentUser object is set early on before a custom user subclass has been registered, it will never be updated with the subclassed user. As the current user loading is asynchronous this can create a race condition, and for some app launches currentUser() will return a PFUser and other times it will return your custom subclass.

This adds a check to verify that the cached user object is of the class that we expect to get. If it isn't, it continues with user loading which will create the correct class.

This all means that currentUser() will return a PFUser before the user subclass is registered, and a MYUser custom subclass after the registration completes. This seems like expected behavior and should prevent hard to track down bugs, especially in Swift projects where the + load method isn't available.

As an aside, it seems this issue may also be fixed by the merging of #5. That has been sitting around for a long time, and this PR should get us by until that old PR can be evaluated and merged.

if (currentUser) {
// Verify that the current user matches our expected registered subclass
Class expectedClass = [[PFObjectSubclassingController defaultController] subclassForParseClassName:@"_User"];
if(expectedClass == [currentUser class]){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should do [currentUser isKindOfClass:expectedClass] here instead of direct class comparison.

@Vortec4800
Copy link
Author

Probably a good idea. I've been working in Swift too much lately. :D

@nlutsenko
Copy link
Contributor

Let's continue the discussion on the linked issue. This looks good and I love the idea, but not sure whether a temporary patch is the right solution.

@Vortec4800
Copy link
Author

Updated as requested, in case we decide to use this.

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 this pull request may close these issues.

3 participants