I have had this showstopper bug. I am not sure if this is an entity issue or a core issue.

There are modules which do not populate all elements of entity_load.

I think that this contributes to the fatal error but I am not sure.

I did a print backtrace on the error. The issue for me is that it is not just one module, a few don't define it.

Array
(
    [0] => Array
        (
            [file] => /var/aegir/platforms/7/servers/drupal-7.14/includes/common.inc
            [line] => 7633
            [function] => entity_get_controller
            [args] => Array
                (
                    [0] => user
                )

        )

    [1] => Array
        (
            [file] => /var/aegir/platforms/7/servers/drupal-7.14/modules/user/user.module
            [line] => 287
            [function] => entity_load
            [args] => Array
                (
                    [0] => user
                    [1] => Array
                        (
                            [0] => 0
                        )

                    [2] => Array
                        (
                        )

                    [3] => 
                )

        )

    [2] => Array
        (
            [file] => /var/aegir/platforms/7/servers/drupal-7.14/modules/user/user.module
            [line] => 362
            [function] => user_load_multiple
            [args] => Array
                (
                    [0] => Array
                        (
                            [0] => 0
                        )

                    [1] => Array
                        (
                        )

                    [2] => 
                )

        )

    [3] => Array
        (
            [file] => /usr/share/php/drush/includes/drupal.inc
            [line] => 138
            [function] => user_load
            [args] => Array
                (
                    [0] => 0
                )

        )

    [4] => Array
        (
            [file] => /usr/share/php/drush/includes/bootstrap.inc
            [line] => 945
            [function] => drush_drupal_login
            [args] => Array
                (
                    [0] => 0
                )

        )

    [5] => Array
        (
            [file] => /usr/share/php/drush/includes/bootstrap.inc
            [line] => 185
            [function] => _drush_bootstrap_drupal_login
            [args] => Array
                (
                )

        )

    [6] => Array
        (
            [file] => /usr/share/php/drush/includes/bootstrap.inc
            [line] => 345
            [function] => drush_bootstrap
            [args] => Array
                (
                    [0] => 6
                    [1] => 7
                )

        )

    [7] => Array
        (
            [file] => /usr/share/php/drush/includes/bootstrap.inc
            [line] => 291
            [function] => drush_bootstrap_max
            [args] => Array
                (
                )

        )

    [8] => Array
        (
            [file] => /usr/share/php/drush/drush.php
            [line] => 79
            [function] => drush_bootstrap_to_phase
            [args] => Array
                (
                    [0] => -2
                )

        )

    [9] => Array
        (
            [file] => /usr/share/php/drush/drush.php
            [line] => 59
            [function] => _drush_bootstrap_and_dispatch
            [args] => Array
                (
                )

        )

    [10] => Array
        (
            [file] => /usr/share/php/drush/drush.php
            [line] => 14
            [function] => drush_main
            [args] => Array
                (
                )

        )

)

Issue fork entity-1667536

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

kevinquillen’s picture

I am getting this same error, but not sure how to get around it. I currently cannot run Drush because that error comes up each time.

kevinquillen’s picture

It keeps tripping on my custom entity, claiming it can't see its controller class. However, dumping entity_get_info() elsewhere shows that it in fact has one. Why then, does this fail?

/**
 * Get the entity controller class for an entity type.
 */
function entity_get_controller($entity_type) {
  $controllers = &drupal_static(__FUNCTION__, array());
  if (!isset($controllers[$entity_type])) {
    $type_info = entity_get_info($entity_type);
    $class = $type_info['controller class'];
    $controllers[$entity_type] = new $class($entity_type);
  }
  return $controllers[$entity_type];
}
kevinquillen’s picture

Now it stops on NodeController.

Just for kicks, I added a ternary to prevent $class from being '' or null:

$class = isset($type_info['controller class']) ? $type_info['controller class'] : 'DrupalDefaultEntityController';

Which then results (drush cc all) in:

WD php: PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server[error]
version for the right syntax to use near 'IN  ('1560'))' at line 2: SELECT base.*
FROM 
{} base
WHERE  (base. IN  (:db_condition_placeholder_0)) ; Array
(
    [:db_condition_placeholder_0] => 1560
)
 in DrupalDefaultEntityController->load() (line 196 of /data/disk/o1/static/drupal/includes/entity.inc).
Drush command terminated abnormally due to an unrecoverable error.                                                                                                          [error]
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IN  ('1560'))' at line 2: SELECT base.*
FROM 
{} base
WHERE  (base. IN  (:db_condition_placeholder_0)) ; Array
(
    [:db_condition_placeholder_0] => 1560
)
 in DrupalDefaultEntityController->load() (line 196 of /data/disk/o1/static/drupal/includes/entity.inc).

I assume 1560 is a node ID, which would be my frontpage.. This is about as far as I have gotten with this error in 3 hours and really do not know where else to look. I am kind of crippled.

How in the world do you fix this?

socialnicheguru’s picture

do you have a short list of modules installed?

Can you list them here?

I had an issue with drupalchat and feedback module. I am sure they are not the only ones though.

I am surprised this has not shown up for others.

PS.
On a side note, PDO errors cripple the system in Drupal 7. Is there anyway around them?

kevinquillen’s picture

I mean it was fine until I updated these modules on Sunday:

  • AddressField
  • Context
  • Delta
  • Entity
  • Geocoder
  • GeoField
  • Pathauto
  • SearchAPI
  • SearchAPISolr
  • Token
  • Omega (theme)

How can you even pin down where the problem is?

socialnicheguru’s picture

I rewrote with debug information:

function entity_get_controller($entity_type) {
  $controllers = &drupal_static(__FUNCTION__, array());
  if (!isset($controllers[$entity_type])) {
    $type_info = entity_get_info($entity_type);
    $class = $type_info['controller class'];
//sng
if(gettype($class) == 'string' || gettype($class) == 'object') {
 $controllers[$entity_type] = new $class($entity_type);
 }
 else  {
print_r(debug_backtrace());
$controllers[$entity_type] = new $class($entity_type);

// when $class is not defined, the $controllers[$entity_type) will not be a valid value
// the backtrace gave me info on which module was invoked right before the major error occurs

        }
  }
  return $controllers[$entity_type];
}
kevinquillen’s picture

It looks like a Context with a PHP condition that uses arg(1) to run a load with the module loader function and not entity_load.

I have changed the code, but cannot clear the cache still to get rid of this. I truncated the cache* tables and it still persists. Is there a Drush cache or something? I have removed the PHP AND disabled the context.

kevinquillen’s picture

Wow, this was a hard one to clear. Once this is up and stuck in the cache, it was very difficult to remove it. I called drupal_static_reset inside a PHP script, causing a segfault (yep), came back and drush cc all one more time- that time it worked. Thank you for your help.

What is the proper protection to keep this from happening?

socialnicheguru’s picture

in #7 where did you change the code? did you change each module? could you cut and paste the snippet here?

this might be something that a lot of modules do, not just those two.

kevinquillen’s picture

It was a Context PHP condition set by a dev, like a block you put PHP code in. It was checking to see if it was on a particular entity detail page, by loading the object with arg(1) (similar to checking for $node with node_load(arg(1)).

socialnicheguru’s picture

do you have a specific line of code where you changed it in context mdoule?

kevinquillen’s picture

I didn't- it was custom code in that condition that I removed.

Was using entity_class_load(arg(1)) and I replaced it with entity_load('my_entity', arg(1))- which cleared it up, seemingly.

socialnicheguru’s picture

hmmm, I am wondering if other modules are doing the same thing.

I was using off the shelf modules.

kevinquillen’s picture

I thought this was a somewhat accepted way of checking if you can load an object on a particular page. I suppose not for custom entities?

kristen pol’s picture

I was getting a similar error when I copied my site over to a new server. After running update.php, it sorted itself out though there were no database updates to run. Weird!

saltednut’s picture

I am seeing the same error on a different line when I try to use entity_save() or entity_delete()

Fatal error: Class name must be a valid object or a string in /drupal-7.14/includes/common.inc on line 7656

Here are some examples that will cause the error:

$entity = entity_load_single('node', 100);
entity_save('node', $entity);
entity_delete('user', 4);

My bad: this was caused by menu callback function conflicts with hook_delete and hook_update.

See: #1694428: U and D in CRUD need working callbacks in Entity JS

kepford’s picture

I was having the same issue as @Kristen Pol and running drush updb && drush cc all cleared it up.

jlporter’s picture

Version: 7.x-1.0-rc3 » 7.x-1.x-dev

I can also confirm this still happens under certain circumstances. The drush updb and cc all afterwards cleared it up.

The only thing that was done prior to fatal wsod, was a feature was enabled that had to use the same field on two content types. This is the only thing we hypothesize that was the underlying problem.

prdctvtxt’s picture

I experienced this issue today. Solved by stopping memcached, restarting apache, truncating cache tables.
Site comes back; start memcached, restart apache.

kevinquillen’s picture

The most common cause I found was with things like Solr and Memcache. If you delete an entity and those caching systems are not updated (through proper API usage, entity_delete etc), attempting to load an entity id that no longer exists causes some nasty problems.

Michsk’s picture

Here is what happend for me;

Custom block snippet before:

function _jumbotron_block_data() {
    $entity_type = arg(0);
    $entity_id   = (array) arg(1);
    $entity      = (array) entity_load($entity_type, $entity_id);
    
    return entity_view($entity_type, $entity, 'jumbotron');
}

The block that used above was displayed on all pages. The problem with that is that when you visited an 404 OR 403 like /admin/ when not being logged in, or any other strange page. I had custom 404 and 403 pages, something like /woops/404. With above code the $entity_type would be woops. Which of course is not right.

Correct code

function _jumbotron_block_data() {
    $entity_type = arg(0);
    $entity_info = entity_get_info($entity_type);
    
    if (! $entity_info) {
        return;
    }
    
    $entity_id   = (array) arg(1);
    $entity      = (array) entity_load($entity_type, $entity_id);
    
    return entity_view($entity_type, $entity, 'jumbotron');
}
mralexho’s picture

One of our developers ran into this issue as well. Although he's running a different version (7.22), this may help -

Like @kepford mentioned, if drush updb and drush cc all doesn't work, try truncating your cache_* tables first.

bfuzze9898’s picture

I run into this problem intermittently, usually because I've done something stupud. I can't promise that's not the case in this instance, but something weird is definitely going on and I am able to reproduce it.

Environment:
Drupal 7.28
PHP 5.3.10-1ubuntu3.11
PostgreSQL 9.1.13

It started when I disabled the Devel module, but this seems to happen across many modules.
First, an error kicked off from the termstatus contrib module, user_access() is undefined (warning sign). I wasn't using that module so I moved it and then this error reared its ugly head.

PHP Fatal error: Class name must be a valid object or a string in /includes/common.inc on line 7853

Ran through the regular gambit (truncate the tables, clear the browser cache, even did the drush updb and drush cc all, mentioned above. Nothing worked.

Had to dive into the code to figure out what was going on:
I won't paste the entire backtrace because it's painful, but it was definitely failing to load the user entity info.
common.inc
entity_load >
entity_load_controller >
entity_get_info >

    // had to disable caching to debug
    if (false && $cache = cache_get("entity_info:$langcode")) { 
      $entity_info = $cache->data;
    }
    else {    
      var_dump(module_list()); // USER MODULE IS LISTED
      var_dump(module_implements('entity_info')); 
/*
      Array
(
    [0] => comment
    [1] => eck
    [2] => node
    [3] => system
    [4] => taxonomy
    // USER IS MISSING (!)
)
*/
      var_dump(function_exists('user_entity_info')); // 
/*
bool(false) // (!)
*/
     $entity_info = module_invoke_all('entity_info'); //@7652
      ...

Adding the following test code which seemed to correct the issue (this is core so not a solution).

      // leave caching disabled
      require_once(drupal_get_path('module', 'user') . '/user.module');      
      module_implements('entity_info', false, true);
      
      $entity_info = module_invoke_all('entity_info'); //@7652

Was able to login now.
I removed all test code from common.inc and flushed the cache, problem comes back!

The solution I settled on was adding these 2 lines to the top of my custom module which apparently is loaded early enough to catch this issue. Not ideal, but it works.
Maybe my experience will save others some time.
Fun stuff.

bfuzze9898’s picture

Word to the wise and not so wise.

I started to notice additional system instabilities with other core and contributed modules with similar entity-info errors. After much deliberation, I found the cause was some custom-module initilization logic written inline instead of inside a hook_init function. When flushing the cache, this logic was calling drupal core functions before all modules were loaded or finished loading, leading to a variety of unexpected behavior (particularly with modules loaded late like wysiwyg).

Hope this helps someone.

ahsanra’s picture

I managed to solve this problem with few steps below.

First step: go to common.inc in includes folder
find the function "function entity_get_info($entity_type = NULL)"

change the line if ($cache = cache_get("entity_info:$langcode")) to if (false && $cache = cache_get("entity_info:$langcode"))
Now this cache is disabled.

next step:

Add the following 3 lines in the else statement above the "module_invoke_all function", so that the whole chunk becomes like below

if (empty($entity_info)) {
if (false && $cache = cache_get("entity_info:$langcode")) {
$entity_info = $cache->data;
}
else {

var_dump(module_list()); // Add this new line
var_dump(module_implements('entity_info')); // Add this new line
var_dump(function_exists('user_entity_info'));// Add this new line

$entity_info = module_invoke_all('entity_info');

Now you will be able to load the page and log in to the admin panel.

Login and Clear the Cache.

You are good to go. It should work like it did for me.

Once you have done the above, revert all the changes.

Thanks,

steveoliver’s picture

For me this was due to PHP version differences (i.e. between 5.3.10 and 5.3.29) where (string) $object (on an object implementing no __toString() method) generated the "Recoverable fatal error" running 5.3.10 and no error running 5.3.29. Keeping such an object from being cast as string was the bug to fix in my custom code. Similar casts of objects to string with certain version of PHP (I don't know which) may be the cause of the different cases above.

alemadlei’s picture

For me, this fixed it, by doing it on mysql

TRUNCATE TABLE cache;

I added code on a module file at the wrong location (it executed as part of the file and then I called die.

After clearing chace from the DB it worked for me.

alemadlei’s picture

For me, this fixed it, by doing it on mysql

TRUNCATE TABLE cache;

I added code on a module file at the wrong location (it executed as part of the file and then I called die.

After clearing chace from the DB it worked for me.

socialnicheguru’s picture

in my original issue, user_load was being passed an array for uid.
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/... says that user_load takes an integer only in D7.
Maybe it was a cached value that cleared up after a cache clear?

duppy.ocio’s picture

#27 worked for me.

Thank you!

emmonsaz’s picture

I had to run updatedb, clear Drupal cache, and then clear memcache to fix this. Thanks @prdctvtxt

dinesh_b’s picture

I cleared table cache , memcache cache and solr too but still error not resolved .
It comes when I make solr search in search result page. This is what I get in logs

Error: Class name must be a valid object or a string in entity_get_controller() (line 7998

Someone please help me.

dinesh_b’s picture

Just created a new Solr instance and it worked.

rsorokine’s picture

This one should work:

drush sql-query "DELETE FROM cache_bootstrap"
drush sql-query "DELETE FROM cache"
drush php-eval "entity_info_cache_clear();"
stateoftheheart’s picture

That worked for me. Thanks!

donavanwilliams’s picture

Thanks @rosrokine

#34 worked for me.

yelvington’s picture

Just leaving this for others who run into this problem:

drush @sitename.env --fire-bazooka --strict=0

Seriously. This forces an aggressive rebuild of the registry (multiple passes, multiple cache clears) and pretty much clears out all the cockroaches. As documented, you should back up the DB first.

dahousecat’s picture

I tried all of the above but nothing worked. Looking at the backtrace the error for me originated from menu.inc.

I put return NULL; as the first line of menu_local_actions() and menu_local_tabs().

I then did a registry rebuild (drush rr) and cleared the cache (drush cc all), and then removed those lines again.

After that is was all fine... hope this might help someone else.

liam morland’s picture

Status: Active » Needs review
StatusFileSize
new959 bytes

The attached patch fixes this issue. There is also a core-level fix proposed in #1982810: Core entity_get_controller gets a NULL controller class.

nitin.k’s picture

Awesome #34.

maxplus’s picture

Hi,
#34 worked for me, thanks

cubeinspire’s picture

If you are facing a similar problem I would suggest to backtrace the error by temporarily hacking the common.inc file with this:

function entity_get_controller($entity_type) {
  $controllers = &drupal_static(__FUNCTION__, array());
  if (!isset($controllers[$entity_type])) {
    $type_info = entity_get_info($entity_type);
    $class = $type_info['controller class'];
    if ($class == NULL){
      variable_set('error_level');
      echo(ddebug_backtrace());
      die();
    }
    $controllers[$entity_type] = new $class($entity_type);
  }
  return $controllers[$entity_type];
}

Module devel required of course. That is how I've found the code that was giving problem and corrected the error.
It was simply due to a entity_load on a null entity type that happened on a particular situation.

andrewtf’s picture

I can vouch for #34, too. Thanks for that! I thought I was going to be in for a long day... (Might still be, it's early.)

hfvd’s picture

I installed the module "modules_weight" and positioned my custom module as last (100). Saved, cleared the cache, and gone was the error. My custom module uses cache_clear_all() so probably that was the problem.

Gnanasampandan Velmurgan’s picture

HI,

#39 This patch worked for me. thanks

alauddin’s picture

#39 patch worked!
Thanks.

liam morland’s picture

Since it is working for you, you could mark it "reviewed and tested by community".

jomarocas’s picture

Status: Needs review » Reviewed & tested by the community

I apply the patch and tested an working good for me, but need apply the following patch for working https://www.drupal.org/files/issues/drupal-entity_get_controller_null_co... in drupal core

updated the issue for tested, but without this patch in core, probably dont working

mglaman’s picture

This should probably have tests added to it, too, correct?

g33kg1rl’s picture

#34 and the patch from #48 cleared up the issue for me. This was preventing me from being able to migrate and upgrade websites on Aegir.

wajdigharbi’s picture

#34 the patch return the following error:
"error: corrupt patch at line 44"

marcoka’s picture

#34 worked for me with php 7.2.1
btw #34 is not a patch, just some drush commands.

zakir.gori’s picture

Following works for me

UPDATE system SET status='0' WHERE name='module_name';
DELETE FROM cache_bootstrap WHERE cid='system_list';

TRUNCATE TABLE cache;
TRUNCATE TABLE cache_admin_menu;
TRUNCATE TABLE cache_block;
TRUNCATE TABLE cache_bootstrap;
TRUNCATE TABLE cache_features;
TRUNCATE TABLE cache_field;
TRUNCATE TABLE cache_filter;
TRUNCATE TABLE cache_form;
TRUNCATE TABLE cache_image;
TRUNCATE TABLE cache_libraries;
TRUNCATE TABLE cache_menu;
TRUNCATE TABLE cache_page;
TRUNCATE TABLE cache_path;
TRUNCATE TABLE cache_rules;
TRUNCATE TABLE cache_token;
TRUNCATE TABLE cache_update;
TRUNCATE TABLE cache_views;
TRUNCATE TABLE cache_views_data;

Thanks

ashique12009’s picture

#28 works for me, thank you.

altagrade’s picture

Issue summary: View changes

Have put the long array between the code tags as otherwise it's impossible to read.

VladimirAus made their first commit to this issue’s fork.

vladimiraus’s picture

Updated to MR as patch was not applying because of comment.

joseph.olstad’s picture

This suggested change looks like a reasonable improvement to me.

joseph.olstad’s picture

#34 has an extra comment update which I think is important. The merge request does not have that.

I'd say go with #34 for the win