Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I'm seeing a lot of the error "Undefined property: stdClass::$timestamp in _drupal_session_write()" in my logs. The error comes from a path/location for a custom module. However, It is unclear to me wether the module is the root of the error since the error somehow seems to come when Drupal attempts to write the session to the database.
Any ideas what the cause might be?
Comment | File | Size | Author |
---|---|---|---|
#23 | undefined-property-timestamp-1078614-23.patch | 745 bytes | geerlingguy |
#19 | session.inc_.patch | 655 bytes | sah62 |
#15 | session.inc_.patch | 666 bytes | sah62 |
Comments
Comment #1
sbrattla CreditAttribution: sbrattla commentedIt seems that _drupal_session_write() in session.inc always assumes that the $user->timestamp exists. Even though this is an unfamiliar territory to me, it seems that $user->timestamp not get's set before the user has received a cookie. This is what i
did to reproduce the problem:
1. Add print_r($user); as the second line in _drupal_session_write() in session.inc.
2. Register a new user and log in as that user.
3. The first request made after the user has logged in shows no trace of the property $user->timestamp. However, the subsequent request does show it along with a few more properties (such as hostname, cache, session and the like).
LIne 173 in session.inc does not check wether $user->timestamp exists, and my log files gets flooded with warnings telling me that the property does not exist.
As far as i can see, this is fairly easy to fix. However, does anyone know about any "pitfalls" with regard to this?
Comment #2
sbrattla CreditAttribution: sbrattla commentedI'm changing this to a bug report, since Drupal assumes that the property always exists even though that is not the case.
Comment #3
amanaplan CreditAttribution: amanaplan commentedDoes your code do something like this?
If so, you are loading a plain user (i.e. account) object as the global $user which is mixing apples and oranges even if the uid is the same. The global $user object has session information. The plain user entity object is just a database select of a user, which you might need to load into a new variable in order to get Field API fields, etc. for the current user. However, if you overwrite the global $user object, you will erroneously remove session information, giving you that error. Simple design solution though, try this instead:
Comment #4
amanaplan CreditAttribution: amanaplan commentedTake a look at http://api.drupal.org/api/drupal/modules--user--user.module/function/use... for specifics.
Comment #5
sbrattla CreditAttribution: sbrattla commentedIndeed, that is what I did. I only thought that user_load would load additional details for the current users (such as custom fields). However, I need to make sure in the future to keep those two instances clearly separated. Thank you for your feedback and help! It probably saved me a few hours :-)
I'll change the category to support request and set it as fixed.
Comment #7
geerlingguy CreditAttribution: geerlingguy commentedI'm still getting this error in the db on many logins, and all I'm doing is calling
global $user;
in my own login form submit callback...I can't tell if anything else could be causing this, though... it's just annoying that my logs include a $timestamp error every time a user logs in.
Comment #8
amanaplan CreditAttribution: amanaplan commentedDoes the error persist when you comment out everything in your custom submit callback function?
Comment #9
geerlingguy CreditAttribution: geerlingguy commentedI'll continue looking into the problem.
Comment #10
geerlingguy CreditAttribution: geerlingguy commentedI removed that hook entirely, and flushed all caches, and I'm still getting the error. Funny thing, though - I don't seem to get the error on my local MAMP environment, but the live server is showing the error. I have the databases synced via drush sql-sync, and the data structure is all the same.
Maybe a PHP version discrepancy or something strange going on?
Comment #11
bochen87 CreditAttribution: bochen87 commentedsubscribe
Comment #12
blasthaus CreditAttribution: blasthaus commentedsub, same issue
Comment #13
NancyDruI'm getting
Notice: Undefined property: stdClass::$timestamp in _drupal_session_write() (line 175
when adding an Article. I am not even looking at the user object.7.10
PHP 5.2.11
MySql 5.5.8-log
Comment #14
batigol CreditAttribution: batigol commentedsame here -
Notice: Undefined property: stdClass::$timestamp in _drupal_session_write() (line 175
of....This notice message is freaking me out !
Comment #15
sah62 CreditAttribution: sah62 commentedI'm seeing this same error in the 7.x branch when users login. This is definitely a bug in session.inc. The simple fix seems to be a check to make sure that $user->timestamp is set before attempting to use it. Here's a 7.x patch that eliminates the login-related error on my site. It's a one-line change that should also work with the 8.x version of session.inc.
Comment #16
batigol CreditAttribution: batigol commentedtested - patch is working for D7.12
Comment #17
Jody LynnI have the same problem in my logs. Patch looks good.
Comment #19
sah62 CreditAttribution: sah62 commentedPatch re-roll with Unix-style line endings...
Comment #20
geerlingguy CreditAttribution: geerlingguy commentedComment #22
sah62 CreditAttribution: sah62 commentedThe patch is failing testing because of a directory name problem caused by my ignorance of how the patch file system should be set up. If someone with more experience in patch development can fix it, please do.
Comment #23
geerlingguy CreditAttribution: geerlingguy commentedI checked out drupal core with git, then made the change in session.inc, and cd'ed to the drupal root directory (the directory with the core directory in it), then said 'git diff > patch-name-here-[issue]-[comment].patch. This should work for any core patch. Of course, YMMV on Windows...
Comment #24
james.williams CreditAttribution: james.williams commentedIssue #1410130: Notice: Undefined property: stdClass::$timestamp in _drupal_session_write() is a duplicate of this one, but some useful discussion about this patch was there.
seanburlington argued that the underlying problem should be resolved and not just hidden by suppressing the warning.
For me, this patch is good since this warning is unnecessary, but the underlying problem should also be identified & perhaps a more relevant/helpful warning thrown instead.
So, when should $user->timestamp be set? It looks to come from the $_SESSION rather than the original account object but I don't fully understand how that gets merged into the user object.
Comment #25
kpa CreditAttribution: kpa commentedThis was my error, I assumed the global $user was the user_load() return.
This fixed for me:
This preserves everything in the global $user object, whilst appending into it the extra details I wanted to add, requiring the user_load().
Comment #26
Steven Jones CreditAttribution: Steven Jones commentedSeems like this issue may be a duplicate now as this issue got fixed as part of #1050746: HTTPS sessions not working in all cases I think?
Comment #27
Jody LynnConfirmed that #1050746 fixed this bit.