Needs review
Project:
MongoDB
Version:
7.x-1.x-dev
Component:
Session
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
4 Apr 2013 at 21:00 UTC
Updated:
7 Jul 2018 at 13:49 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #0.0
protools commented#
Comment #1
marcingy commentedThis was caused by the following commit http://drupalcode.org/project/mongodb.git/commit/e68769e I am assuming the code in mongodb_session_user_update which the above calls (mongodb_session_user_insert) needs to be move into the inc file and be renamed appropriately.
Comment #2
MantasK commentedI took code from stable version with small change:
I removed '_id' => (int) $account->uid, from '$set'
as it is not necessary and gives error (maybe I have newer MongoDB verison)
aslo in newest dev version there was syntax error
Comment #3
jyee commentedRerolling #2 and updating to pass $edit by reference and $category per the api spec.
Comment #4
jyee commentedI had a few errors with the patch in #3. This should resolve them.
Comment #5
dyannenovaThe patch in #4 needs an update hook for users. Other than that it works well.
Comment #6
jyee commentedNew patch with an update hook to update (load and save) user accounts.
Note: You may need to add the patch from https://drupal.org/node/1922578#comment-7926955 if you're using mongodb_field_storage, otherwise the update may not properly retain user roles.
Comment #7
cloudbull commentedI have this while applying #6
is that the dev updated ?
Comment #7.0
cloudbull commented2
Comment #8
marcingy commentedThis does not need an update hook as people login in sessions will migrate naturally to mongo. The joys of schemaless db :)
Comment #9
jyee commentedActually, it does need the update hook because when a user logs in, the only thing being updated is the login, not the entire user document. See: http://drupalcode.org/project/mongodb.git/blob/79ee6b5:/mongodb_session/...
There's a bug with the existing code where user roles are not being saved in mongo. Without the update hook, those users login but do not have the correct permissions. The update hook corrects those user documents so that they follow the same structure/schema as created by mongodb_session_user_update()
Comment #10
marcingy commentedAh my bad....however why not when you query mongo in the update hook check to see if $roles is present in the user object that is returned and if it is no need to run user save. And too be honest there is really no need to go through user_save instead just lift out the logic in hook_update and put it directly in the update function. On large data collections which mongo has normally the approach at the moment is not going to be performant. We have to remember any installs prior to the commit that removed this feature will have the data in place for roles and also anyone running dev version will very likely reverted the problematic commit as the code fatals currently so an update function for broken code seems pointless....
Comment #11
slashrsm commentedI agree with @marcingy about user_save(). It should be avoided if possible.
I am wondering... could we use upsert with that?
Comment #12
beefheartfan commentedNot sure if I'm posting this in the right spot, but the issue I'm experiencing is related to the code in this patch, so here goes...
I noticed that when users logged into my site, the Mongo Session module successfully saves their user roles in the field_current.user collection like so:
However, if I update the edit the user (at user/xxxx/edit), the role names are dropped and it just saves the rids to Mongo, like this:
I believe this has to do with the way the roles are updated in mongodb_session_user_update(). The $save array is being created using a Union like this:
But because the $account array at this point only has the rids stored and the 'roles' key already exists, it does not apply the update to $roles that is obtained through _mongodb_session_get_roles();
I was able to get it to work by just updating the 'roles' key outside of the union like this, but there is probably a better way to do it so thats why I didn't just create an update to the earlier patch:
If I have the Field Storage module turned on, I also needed to make a similar update the in mongodb_field_storage.module file....
Comment #13
cracu commentedSame problem here...
Instead of:
change with:
Comment #14
Georgique commentedHere is patch according last comments.
Comment #15
fgmThis patch no longer applies: there is already a mongodb_session.install.
Comment #16
Anonymous (not verified) commentedI just downloaded the latest dev, applied the patch cleanly, & sessions now work in Mongo without the fatal error. RTBC
Comment #17
Anonymous (not verified) commentedI spoke too soon. Somehow it worked for me for about an hour after applying this patch, then all kinds of craziness, because indeed, the install file was borked.
Comment #18
majorrobot commentedI've rerolled the patch in #14 using the latest dev and tried it out (attached for reference).
However, I think we still need the patch the from #1922578: Field Storage module does not store user roles. Otherwise, new users will never have the correct roles stored. The issue is that hook_user_insert() is called before roles are saved in user_save().
Further complicating the issue is that hook_user_insert() may also be called before mongodb_field_storage_field_storage_write(). Which is what happened on my local machine. So, mongodb_session_user_update() may try to update a user record that does not exist yet.
With this in mind, I wonder if it makes sense to use the MongoDB Session module to save/update roles at all. Sites may use MongoDB Field Storage and choose not to use MongoDB Session. Plus, if we're dealing with a what's basically a field (and a highly important one, at that), Field Storage seems to be the place for this.
So, I suggest:
Including a patch that does all this.
It could be that I'm missing something here, so I'd be happy to hear others' take on this approach.
Comment #19
majorrobot commentedComment #20
nehapandya55 commentedHi,
I got same issue #14 works for me.
Comment #21
fgm@majorrobot : no one answered your #18 patch, which is supposed to be complete. Do you think it should be merged ?