Receiving twice each of the following after setting/saving some configuration combinations:
Notice: Trying to get property of non-object in comment_notify_form_user_form_alter() (line 215 of …/comment_notify/comment_notify.module) …
Notice: Trying to get property of non-object in comment_notify_form_user_form_alter() (line 231 of …/comment_notify/comment_notify.module) …
Steps to reproduce:
1. Enable the module.
2. Save a user.
At first I thought it was because of a particular configuration I set up with comment_notify but it happens right after the module is installed without any configuration being done for the module or for the per-user settings.
The notices sometimes appear after setting some combinations of settings again, but this is hard to reproduce, and eventually the notices go away.
Comment | File | Size | Author |
---|---|---|---|
#15 | comment_notify-user-settings-defaults-2865943-15.patch | 841 bytes | simonholt83 |
| |||
#14 | comment_notify-user-settings-defaults-2865943-14.patch | 1.12 KB | simonholt83 |
| |||
#10 | comment_notify-n2865943-10.patch | 419 bytes | DamienMcKenna |
|
Comments
Comment #2
TommyK CreditAttribution: TommyK as a volunteer commentedI think I figured this one out. We are looking at
comment_notify_get_user_notification_setting($uid)
incomment_notify.inc
.I don't understand
&drupal_static(__FUNCTION__)
much, but from my interpretation of the API docs (https://api.drupal.org/api/drupal/core%21includes%21bootstrap.inc/functi...) because the module was just installed, the function is being called for the first time after a reset and won't have the right information available. The$users
object isNULL
at this point.We need to offer a condition for that, and the defaults should probably be supplied in this case.
Comment #3
gregglesThe
&drupal_static(__FUNCTION__)
will get called once per page, it's a way to do caching inside of a single request cycle. I think that's slightly different than the scenario you described (being right after the module is installed).Your change looks sane to me, though, and I'm inclined to commit it.
Did it fix the notice for you?
Comment #4
TommyK CreditAttribution: TommyK as a volunteer commentedApologies for the delay on this, but yes, once I made that change there was no notice even immediately after install.
Comment #5
MartinMa CreditAttribution: MartinMa as a volunteer commentedJust have the same message now, but months ago, i never have seen it on my (old) installation (with composer manager which is now abandoned). just moved to a installation with set up with composer ...
Comment #6
DamienMcKennaComment #7
DamienMcKennaFYI #2925405: Notice in comment_notify_form_user_form_alter() function is an alternative way of handling this.
Comment #8
DamienMcKennaAnd #2850935: Error when the user has been created and edit his profile for first time seems to be another duplicate.
Comment #9
greggles@DamienMckenna - is there one you think should be committed? Question to anyone, really.
Comment #10
DamienMcKennaI think this would be a better approach, less duplicate code 'n stuff.
Comment #11
DamienMcKennaOf course I just realized that would require a bunch of internal API changes elsewhere..
Comment #12
anawillem CreditAttribution: anawillem commentedHi Damien - when you say there are other API calls that will need fixed, are you saying that this patch will break other things, or that this patch is fine, but there are other places that need it as well?
Comment #13
DamienMcKenna@anawillem: I think the problem is that the default isn't loaded properly across the module as a whole, though it has been almost a year since I last looked at it.
Comment #14
simonholt83 CreditAttribution: simonholt83 as a volunteer commentedThe problem with the patch in #10 is that it will prevent comment_notify settings from being saved from the user form. This is because
comment_notify_get_user_notification_setting()
is also used when updating comment_notify settings, to check for existing settings for a user. So if it always returns something it will always try to do an update incomment_notify_set_user_notification_setting
Instead we should just load the defaults directly from the form_alter, if there was no settings found for the current user being edited.
Comment #15
simonholt83 CreditAttribution: simonholt83 as a volunteer commentedUpdated patch to fix exception on user register form.
Comment #16
anawillem CreditAttribution: anawillem commentedThank you @simonholt83!!!
Comment #17
AlexJ CreditAttribution: AlexJ as a volunteer commentedHi, I'm getting this notice when saving a new role to a registered user with 8.x-1.0-beta2+0-dev,
"Notice: Trying to get property 'node_notify' of non-object in comment_notify_form_user_form_alter() (line 215 of ..." and also
"Message Notice: Trying to get property 'comment_notify' of non-object in comment_notify_form_user_form_alter() (line 231 of ... "
Can I use this patch now too?
Comment #18
simonholt83 CreditAttribution: simonholt83 as a volunteer commented@AlexJ Yes, the patch should fix the notices you mention.
Comment #19
gnugetThis was fixed at #2925405: Notice in comment_notify_form_user_form_alter() function
Thanks!