When create multiple new entities of the same type with different types of bundles as it will more than likely happen with field collections there is conflicts in the caching which results in the fields language being returned as 0.

When entities have been saved the items will not conflict as they will all have unique ids, but when they are new entity_extract_ids() will return as id of 0 for every entity. and this means if you have 2 new entities of different bundles the first will set the cache, but the second will try and use the first cache.

The solution that I have added is to make the bundle as a part of the cache. this will mean that on new entities will be inserted uniquely, but in the case of existing entities it will only add a single additional level which should have no impact on performance other than an additional level of array.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gordon’s picture

Status: Active » Needs review

Status: Needs review » Needs work

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

gordon’s picture

Status: Needs work » Needs review

patch_commit_70601e386f2d.patch queued for re-testing.

james.williams’s picture

Issue summary: View changes

I just ran into this -- I totally agree with gordon and his approach, and the patch looks good and works fine for me.

recrit’s picture

Review patch #5 on #2201251: field_language shouldn't cache display_languages for new entities - This patch handles new entities and revisions. The bundle key for the static cache should not be needed since an existing id would not be able to have multiple bundles, and a new entity should not be cached.

james.williams’s picture

james.williams’s picture

Version: 7.12 » 7.x-dev
FileSize
1.43 KB

New patch that includes caching by revision IDs too (#2069439: Static cache in field_language() should key by $vid as well as $id).