Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
I get the following WSOD-inducing error when I try previewing a comment as an anonymous user in Drupal 8 dev (as of Oct. 13, 2013):
Fatal error: Call to a member function id() on a non-object in core/modules/comment/comment.module on line 1371
It looks like comment.module is still using global $user;
, which won't work properly (I don't think) for anonymous users with methods like ->id()
.
This is interfering with my ability to write tests for the Honeypot module; see: #2036501: Don't run Honeypot checks on form previews.
Comment | File | Size | Author |
---|---|---|---|
#8 | comment-preview-anon-2111163-8.patch | 1.91 KB | geerlingguy |
#3 | comment-preview-anon-2111163.fail_.patch | 1.25 KB | larowlan |
#3 | comment-preview-anon-2111163.pass_.patch | 1.88 KB | larowlan |
Comments
Comment #1
BerdirYes, it does. It's $account, not global $user that is accessed here, and there are multiple things that could be assigned to it.
It's more likely that the user_load_by_name() fails and returns NULL.
Comment #2
larowlanfixamakating
Comment #3
larowlanShould be fail/pass.
Thanks for reporting!
Comment #4
andypostGreat!
Comment #5
geerlingguy CreditAttribution: geerlingguy commentedIs it possible to also add a test of an anonymous user posting a preview comment, so this doesn't sneak in again?Nevermind, I noticed you have it post a comment by the anonymous user with preview required. That suffices! RTBC +1.
Comment #6
tstoecklerSo the resulting code in
comment_preview()
with the patch is:It *feels* like this could be simplified somehow, but I couldn't actually think of a way how, so just posting here for reference.
Patch totally looks good.
Comment #7
catchWe never actually use anything from drupal_anonymous_user(), so it looks like we could change this to something like:
Comment #8
geerlingguy CreditAttribution: geerlingguy commentedThat makes sense.
Comment #9
tim.plunkettYep, looks great! Thanks.
Comment #10
webchickGreat work!
Committed and pushed to 8.x. Thanks!
Comment #11.0
(not verified) CreditAttribution: commentedFixed formatting.