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.
I'm getting a notice from the OG module saying "Trying to get property of non-object in og_get_groups_by_user". I will provide a patch to fix it.
Comment | File | Size | Author |
---|---|---|---|
#1 | 2193713-og_get_groups_by_user-1.patch | 491 bytes | guillaumev |
Comments
Comment #1
guillaumev CreditAttribution: guillaumev commentedHere is the patch.
Comment #2
amitaibuThat looks wrong -- if we are iterating over $og_memberships they should be valid ones. Maybe before this we are getting somehow invalid $og_memberships?
Comment #3
jmev CreditAttribution: jmev commentedI'm getting the same error. What's the status of this? Is the patch in #1 needed, usable, dangerous?
Comment #4
amitaibuThe patch seems to be fixing and issue that comes from somewhere else. Can you describe the steps to reproduce.
Comment #5
jmev CreditAttribution: jmev commentedAmitaibu, I got the impression from your previous comment that the patch was wrong, but I'll try it. Thanks.
Comment #6
amitaibuThe patch is indeed wrong.
Comment #7
amitaibuCorrect status
Comment #8
okin CreditAttribution: okin commentedI'm getting the same error. This occurs when someone unsubscribe from og resulting with a NULL value in og_memberships array.
Comment #9
furiel CreditAttribution: furiel commentedamitabu, may I ask you to reconsider using that patch?
I confirm that okin has written earlier, issue comes when you call og_get_groups_by_user()
during the hook_og_membership_delete().
The issue is that the just deleted subscription is in the $og_memberships list as a null, that's why we cannot access its property.
Other than that null value, the content of the array is fine! That's why the patch does the job!
The php notice is the minor thing. The major part is that after the property access failure the function returns null, meaning we lose the valid subscriptions too for the execution.
This can break some logics in the sites, and essentially makes og_get_groups_by_user() unusable after hook_og_membership_delete() without any workaround.