Entites don't receive the new UUID property.

When loading an entity the new field isn't selected from the database because it's missing from the schema_fields_sql entry in the entity type info array.

This array is built up in entity_get_info() based on the database schema. Entity UUID adds the new fields to the schema through hook_schema_alter(). The hook decides which entities should have the fields added to by checking the entity typoe info array for the UUID key. So hook_schema_alter() also calls out to entity_get_info(). On the second call the function automatically returns the static cache built up from the first call even though the first call hasn't finished firing yet. In fact, the first call hasn't called out to hook_entity_info_alter() yet so the entity type array won't have the UUID key and therefore the fields don't get added to the schema.

Comments

Dean Reilly’s picture

StatusFileSize
new1.06 KB

Here's a patch which gets stuff working if you're just using the interface configuration but it doesn't work when using hooks and it hardcodes the field names.

arnested’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.61 KB

Added extra check for existence of properties to avoid PHP noticies.

zkday’s picture

Thanks for patch.
Committed && Pushed!

zkday’s picture

Status: Needs review » Closed (fixed)
yched’s picture

Still seeing the issue even in 7.x-1.0, which contains the patch here.

AFAICT, the issue is that entity_uuid_schema_alter() calls entity_info() to begin with, so I'm not sure how the patch was supposed to make things better ?

captainack’s picture

Status: Closed (fixed) » Needs work

Agreed. I'm definitely still seeing this problem too.

This patch still has hook_schema_alter() calling entity_get_info(), which relies on a fully prepared schema (and worse yet, caches its incomplete result), which is the root of the problem.

The odd thing I'm trying to understand now is that I only see this problem intermittently. 80% of the time everything's fine, and 20% of the time after I clear the cache the problem arises (and won't go away until after several cache clears). And every so often it pops up while I'm deploying my features, and so I need to just kill the site and redeploy. I can see why it doesn't work sometimes, but I can't see why it's working sometimes.

Anyway, it would seem to me that invoking the entity_info hook in place of the entity_get_info() call should get us as much as we need. I'll try it out under a few conditions to see how that behaves (module install, cache clear, features deployment where the entity_uuid variable is changed, etc).

captainack’s picture

Status: Needs work » Needs review
StatusFileSize
new1.96 KB

Here's a patch I created that takes the same approach as the committed patch, but that also purges all references to entity_get_info() by invoking hook_entity_info instead. I think this should be safe performancewise, since this should only happen with a cleared cache (at least with my look through the code and a little testing).

I tested module installation, enabling a feature that sets the entity_uuid variable, and cache clears.

letapjar’s picture

The patch in #7 applied for me and fixed my intermittent problem with deploying between 2 drupal sites.

Previous to this patch - sometimes I would get a UUIDEntityException about trying to save entities with missing or invalid uuids despite the uuid existing.