line 244 in field_sql_norevisions.module fails if $entity_info['entity keys']['bundle'] is empty, which was the case for user bundle

242: $entity_info = entity_get_info($entity_type);

244: if(empty($enabled_entity_bundles['field_sql_norevisions_' . $entity_type .'_' . $entity->{$entity_info['entity keys']['bundle']} . '_enabled'])) {

$entity_info['entity keys']['bundle'] is empty, so it tried to access empty property of $entity object

I changed line 244 to:

if(empty($entity_info['entity keys']['bundle']) || empty($enabled_entity_bundles['field_sql_norevisions_' . $entity_type .'_' . $entity->{$entity_info['entity keys']['bundle']} . '_enabled'])) {

so it falls back to "normal SQL storage function" , which saves the user object correctly

maybe the error comes from entity_get_info('user') and is not related to field_sql_norevisions?? Have no time to dig deeper...

I have set
Disable SQL revisions for User entity bundles
[X] User
in admin/config/system/field_sql_norevisions/field_sql_norevisions_entity_settings

Comments

rvelhote’s picture

I am testing this module and had the same problem today.

For the user entity the $enabled_entity_bundles variable returns

field_sql_norevisions_user_user_enabled

but in the user entity the $entity_info['entity keys']['bundle'] is empty so we just have to concatenate the correct full string and maintain the thing. Most likely it will break in case this pattern is invalid for another entity type.

I fixed it (well... hacked :P) like this (sorry, no GIT diff).


242. $entity_info = entity_get_info($entity_type);
243. 
244. if(empty($entity_info['entity keys']['bundle'])) {
245.     $entity_info['entity keys']['bundle'] = $entity_type;
246.     $entity->{$entity_type} = $entity_type;
247.  }
antongp’s picture

Status: Active » Needs review
StatusFileSize
new1.1 KB

Hi! Why not to use entity_extract_ids() instead?

antongp’s picture

Priority: Normal » Major

Hi

Could you please review the patch from my previous comment and apply it to the 7.x-2.x or solve the problem in some "more proper" way.

Issue is related not only to user entity type, but to any entity type which defines only one bundle and as result do not provide $entity_info['entity keys']['bundle'] in the hook_entity_info() implementation ('bundle' property is optional). It's enough to have at least one field attached to such entity type/bundle and Field SQL norevisions module enabled (so it is even not needed to enable this entity type on the settings page to not use revisions) to cause the issue. It causes fatal error, for example, on saving of account via form or programmatically...

Marking issue as major... Thank you

pwaterz’s picture

Status: Needs review » Closed (fixed)

committed http://cgit.drupalcode.org/field_sql_norevisions/commit/?id=8681089

Rolling out 7.x-2.1 today as this is a major bug

  • Commit 8681089 on 7.x-2.x by pwaterz:
    Fixing issue with user entities erroring out #2238619
    
antongp’s picture

Thanks much! Looks there are no major issues in 7.x-2.x now (really cool!), only a few minor (would be nice to have them fixed as well :)).