entity_defaults_rebuild triggers another entity_defaults_rebuild causing an infinite loop

Created on 1 April 2016, about 8 years ago
Updated 14 November 2023, 8 months ago

I've tried to enable Diff module and the code went to loop. This also happening when I'm doing feature-update from drush.
It's just rebuilding caches over and over again and the code goes over 5000 levels deep.

Here is the main issue:

   17.7711  297204736  14. entity_flush_caches() includes/module.inc:934
   17.7830  281430864  15. entity_defaults_rebuild($entity_types = ???) entity/entity.module:1085
   57.1516  335722104  16. _entity_defaults_rebuild($entity_type = 'rules_config') entity/entity.module:857
   58.2322  401386312  17. entity_delete($entity_type = 'rules_config', $id = 'rules_foo') entity/entity.module:898
   58.2322  401386680  18. entity_delete_multiple($entity_type = 'rules_config', $ids = array (0 => 'rules_applicant_rule_somebody_else')) entity/entity.module:316
   58.2323  401387000  19. RulesEntityController->delete($ids = array (0 => 'rules_foo'), $transaction = ???) entity/entity.module:338
   58.2359  401387744  20. EntityAPIControllerExportable->delete($ids = array (0 => 'rules_applicant_rule_somebody_else'), $transaction = class DatabaseTransaction { protected $connection = class DatabaseConnection_mysql { ... includes/rules.core.inc:276
   58.2551  401399872  21. entity_defaults_rebuild($entity_types = array (0 => 'rules_config')) entity/includes/entity.controller.inc:890

So basically entity_defaults_rebuild() is called first from entity_flush_caches(), then while rebuilding, it's calling again entity_defaults_rebuild() on Entity delete.

Affected code:

entity.module

function entity_flush_caches() {
  entity_property_info_cache_clear();
  // Re-build defaults in code, however skip it on the admin modules page. In
  // case of enabling or disabling modules we already rebuild defaults in
  // entity_modules_enabled() and entity_modules_disabled(), so we do not need
  // to do it again.
  // Also check if rebuilding on cache flush is explicitly disabled.
  if (current_path() != 'admin/modules/list/confirm' && variable_get('entity_rebuild_on_flush', TRUE)) {         
    entity_defaults_rebuild();                                                                                   
  }
  ...

which triggers code in includes/entity.controller.inc on RulesEntityController->delete():

 public function delete($ids, DatabaseTransaction $transaction = NULL) {
    $entities = $ids ? $this->load($ids) : FALSE;
    if ($entities) {
      parent::delete($ids, $transaction);
  
      foreach ($entities as $id => $entity) {
        if (entity_has_status($this->entityType, $entity, ENTITY_IN_CODE)) {
          entity_defaults_rebuild(array($this->entityType)); // HERE!!!                                                  
          break;
        }
      }
    }
  } 

And this goes endlessly on each entity_flush_caches().

πŸ› Bug report
Status

RTBC

Version

1.0

Component

Core integration

Created by

πŸ‡¬πŸ‡§United Kingdom kenorb

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024