I have need for calling og_get_entity_groups() on a set of entities, some of which are fully loaded, some of which do not yet exist.
og_load_entity() calls entity_extract_ids() but does not check to see if the result is NULL. Passing in array(NULL) causes a nice Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 181 of /var/www/d7/includes/entity.inc).

I'm not sure what the code calling og_load_entity expects as a failure response, or if it ever does, so I won't venture to write a patch just yet. NULL or array() would be my guess.

CommentFileSizeAuthor
#1 og-1368930-1.patch493 bytestim.plunkett

Comments

tim.plunkett’s picture

Title: Fail gracefully when loading a stub entity » Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load()
Status: Active » Needs review
StatusFileSize
new493 bytes

Changing the title for discoverability.
Try this patch?

amitaibu’s picture

Hi Tim :)

> I have need for calling og_get_entity_groups() on a set of entities, some of which are fully loaded, some of which do not yet exist.

Why do you need to call og_get_entity_groups() on new entities to begin with?
I'm not sold on this patch, because the API assumes you are sending an existing entity -- as a new entity anyway won't have groups associated with it. Am I missing something?

tim.plunkett’s picture

Hey Amitai!

I realize what I explained (and what I'm doing) is bizarre.

But I'm passing around shallow copies of other entities. For example, a taxonomy term with only the tid present. When there is no tid, nothing explodes.
With og, if there is a gid associated, it works fine, but for others, it throws the above error.

Someone else in IRC reported the same error, probably under more usual circumstances. Hopefully they'll chime in here...

If not, feel free to 'won't fix' and I'll add an additional check in my code.

amitaibu’s picture

Status: Needs review » Closed (won't fix)

> If not, feel free to 'won't fix' and I'll add an additional check in my code.

I'll do that, as I think that's a bit too much "babysitting" for that API function to do. Sorry ;)

iaminawe’s picture

This patch worked for me to resolve this - only other way looked like it was going to involve a core patch so grateful for this - thank you