-
-
Notifications
You must be signed in to change notification settings - Fork 167
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
getRolesForUser - "Cannot read property '_id' of undefined" on client after edit #308
Comments
If you have a reproduction you could link to that would help. Otherwise, could you post the "readable" javascript around where the exception is thrown, please? |
The line that's crashing in roles_common.js is line 780:
However, the code automatically runs a second time with the roles array populated with the role assignment, which allows the code to work fine and the page to render correctly. I think the app is reacting to the old roles being deleted by |
I've myself tested it here, and it only occurs when having a role-assignment without role - which is pretty weird. Can you please confirm this - and also (in case you have it) look at a place this could come from? A sandbox application, where I could try this out would be nice. |
I've experienced the same problem, but only when my app is open in two different tabs or browsers. And if it's two tabs in the same browser, then the order of the tabs makes a difference. No, really! I tested it like 15 times! I am using observeChanges to dynamically track user roles based on whether their email address is verified:
The 'verified' role has been created in advance and works fine. If I run my app in a single tab, everything works. I verify an email address in one browser tab, while another is open on the app, getRolesForUser throws the error. I also saw the error appear in Firefox when I verified an email address in Chrome. I am currently working around this by wrapping getRolesForUser in a try...catch block. If I only have one browser / tab open on the app, there is no problem. I assume that there is some timing issue whereby addUserToRoles does not operate atomically but instead performs two database operations and a different threaded client can stumble in the gap. |
@Shelagh-Lewins or @cormip would you have time to write a sample sandbox for this? @cormip you describe it as "running in a server method". What do you mean by this? Is it in a Meteor method? If yes, are you sure this code is not run by the client first - see https://guide.meteor.com/methods.html#call-lifecycle? @Shelagh-Lewins For your code it looks quite straight forward to be only available on the server. If you yourself want to dive in, here's the only place I add a role to the system: https://github.com/Meteor-Community-Packages/meteor-roles/blob/master/roles/roles_common.js#L478 The failing code (https://github.com/Meteor-Community-Packages/meteor-roles/blob/master/roles/roles_common.js#L780 I suppose it's a race condition, which are usually hard to reproduce. Creating a sandbox project would be a great time saver to us because we don't have to spend time creating an environment where this might fail. Just create a new Meteor project, make sure you have all the necessary components to reproduce this bug and upload it somewhere we can access it - e.g. to github. |
This issue should've been fixed in the just published version |
I have a client-side "users" table that reactively displays the Meteor User accounts (name, email) and their roles. My template calls Roles.getRolesForUser() to retrieve each user's roles. Everything works fine on initial load.
However, when a user's roles are updated, i.e.
Roles.setUserRoles(user._id, roles)
, via a server method, I get a console error on the client when the table reactively updates itself:I am also null-publishing the users' roles:
Any thoughts on how to address this? It seems like it may be a race condition where the user's roles are removed (and then added) while Roles.getRolesForUser()is running?
The text was updated successfully, but these errors were encountered: