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.

Files: 
CommentFileSizeAuthor
#4 entity_cache_profile2.patch1.94 KBfago
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch entity_cache_profile2.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#4 entity_cache_og.patch1.38 KBfago
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch entity_cache_og.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.
[ View ]
#3 entity_cache_entity.patch1020 bytesfago
PASSED: [[SimpleTest]]: [MySQL] 327 pass(es).
[ View ]

Comments

Title:Cache rebuild troublesavoid 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().

adding tag

Status:Active» Needs review
StatusFileSize
new1020 bytes
PASSED: [[SimpleTest]]: [MySQL] 327 pass(es).
[ View ]

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.

StatusFileSize
new1.38 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch entity_cache_og.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.
[ View ]
new1.94 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch entity_cache_profile2.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

attached are patches for profile2 and og.

Status:Needs review» Needs work

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

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

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.

Thanks Amitaibu for fixing og and message.

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

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

Let's commit #3 once beta11 is shipped.

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.

Is there still a need for this patch?

What modules are we still waiting on?

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

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

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.