I've encountered some strange cache rebuilding problems with Entity API modules like Field collections, Profile2, Message and OG. At the end of the cache rebuilt some information (e.g. Profile2 bundle related info) was missing, which is caused by some entity_info_alter hooks that use some other API functions that are based on entity info, although the entity info isn't completely rebuilt yet.

One concrete scenario is described in the EVA issue queue (#1286022: Cache rebuild dependency issues), but I will close the issue there, as it should be fixed in the Entity API.

In order to solve the problem, the way bundles are added to the entity info needs to be re-worked. It should be avoided that API functions with dependencies to entity info are ever used in such a hook.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fago’s picture

Title: Cache rebuild troubles » avoid entity_load() during entity info cache rebuilds

Yep, this cache-rebuilding issue seem to pop up again and again. Even if uuid is able to workaround, let's try to break that ugly interdependency and follow core by avoiding the entity-info-alter hack and don't use entity_load() for getting bundle entities. E.g. core uses taxonomy_vocabulary_get_names() in taxonomy_entity_info() to bypass this issue. Bypassing entity-load() is not ideal and a hack too, but at least we can do a way with that inter/self-dependency causing weird issues.
As clean solution I think we should do hook_entity_bundle_info() as proposed in #1092192-24: Using hook_entity_info_alter to add the bundles prevents some modules from altering entities. But that's of course not on the table for d7.

However, in order for that to work with exportables we need to get #1267070: Lazy-rebuilding the defaults for exported entities might not be desirable in first. Given that, exportables should be synced already to the database when the cache is rebuilt during module installation (needs verification).

Then, once this works all the modules (Field collections, Profile2, Message and OG) need to be updated to follow that. Field-collection really is a separate issue though, as it makes use of field_info_field(), but we should be able to trigger entity-info-rebuilding there by fixing it to use field_read_fields().

fago’s picture

adding tag

fago’s picture

Status: Active » Needs review
FileSize
1020 bytes

ok, here is a patch which remove the work-a-round from the entity api.

I don't think there is a hurry to commit this patch though, first modules that use bundle-entities like profile2, og and message should adapt.

fago’s picture

attached are patches for profile2 and og.

Status: Needs review » Needs work

The last submitted patch, entity_cache_og.patch, failed testing.

amitaibu’s picture

@fago,
So I can already commit this to OG/ Message, or is the patch in #3 needed first?

fago’s picture

Status: Needs work » Reviewed & tested by the community

Committing the patches now is fine, I've just committed the profile2 patch.

Committing #3 not now does no harm, moreover it requires all used contrib modules to be fixed. So let's postpone it for a while and make sure we fix all the contrib modules now.

fago’s picture

Thanks Amitaibu for fixing og and message.

I've just fixed field-collection, see
http://drupalcode.org/project/field_collection.git/commit/a2214e9

fago’s picture

Also fixed the testing module, the docs and created a change notification.

Let's commit #3 once beta11 is shipped.

zhangtaihao’s picture

Might be worth keeping in mind that the hook documentation could be updated to highlight this issue.

After this has been rolled out, of course.

Simon Georges’s picture

Is there still a need for this patch?

tim.plunkett’s picture

What modules are we still waiting on?

Bert Bastiaan’s picture

#4: entity_cache_profile2.patch queued for re-testing.

hkirsman’s picture

Can this be related to realname module bug where after clearing the cache, list of all tokens are gone under realname admin page?

fago’s picture

Status: Reviewed & tested by the community » Fixed

ok, there was plenty of time for the releases of the modules to ship. So I've committed #3.

Automatically closed -- issue fixed for 2 weeks with no activity.