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.

CommentFileSizeAuthor
#1 2193713-og_get_groups_by_user-1.patch491 bytesguillaumev
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

guillaumev’s picture

Status: Active » Needs review
FileSize
491 bytes

Here is the patch.

amitaibu’s picture

That looks wrong -- if we are iterating over $og_memberships they should be valid ones. Maybe before this we are getting somehow invalid $og_memberships?

jmev’s picture

I'm getting the same error. What's the status of this? Is the patch in #1 needed, usable, dangerous?

amitaibu’s picture

The patch seems to be fixing and issue that comes from somewhere else. Can you describe the steps to reproduce.

jmev’s picture

Amitaibu, I got the impression from your previous comment that the patch was wrong, but I'll try it. Thanks.

amitaibu’s picture

The patch is indeed wrong.

amitaibu’s picture

Status: Needs review » Needs work

Correct status

okin’s picture

I'm getting the same error. This occurs when someone unsubscribe from og resulting with a NULL value in og_memberships array.

furiel’s picture

amitabu, 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.