rules_watchdog can fire rules for incompletely loaded modules if triggered during module_load_all

Created on 30 June 2014, almost 11 years ago
Updated 9 February 2025, 3 months ago

I was baffled by a whitescreen when I enabled a module that I was working on. My php error log told me:
Call to undefined function entity_crud_get_info() in /home/chris/projects/bathroom-city/sites/all/modules/entity/entity.rules.inc on line 96
(entity_crud_get_info() is defined in entity.module)

A stacktrace told me the error was coming from _drupal_error_handler() >> _drupal_error_handler_real() >> _drupal_log_error() >> watchdog(), which was invoking hook_watchdog to get to rules_watchdog() >> rules_invoke_event('watchdog') >> rules_get_cache() >> RulesEventSet::rebuildEventCache() >> rules_fetch_data('event_info'), invoking hook_rules_event_info to get entity_rules_event_info()

In other words, the error was occuring within the error handler.

The error handler was handling an error raised during drupal_bootstrap() >> _drupal_bootstrap_full() >> module_load_all() >> drupal_load()

(This error turned out to be an incorrect filename in an include_once() in my .module file. But that's not directly relevant to this bug report.)

So as far as I can tell, drupal had loaded some but not all of the modules when the initial error occured; then as part of the error handling, it invoked a rule, part of which was defined in the entity module. But the entity module itself had not loaded by this point, even though the rule definition which pointed to entity.rules.inc was present (maybe just in the cache? although I tried clearing all caches and it didn't fix the problem.) And so handling the rule caused this second error.

I can see a number of possible solutions here, although not necessarily within the purview of the rules module.
- Change the behaviour of watchdog() during module_load_all so as not to invoke hook_watchdog
- Change the behaviour of rules_invoke_event during bootstrap to be more careful about what rules/modules to invoke
- Change the behaviour of rules_invoke_event generally so that it checks whether a module has actually been loaded before it fires one of its events

πŸ› Bug report
Status

Closed: outdated

Version

2.0

Component

Rules Core

Created by

πŸ‡¬πŸ‡§United Kingdom chris@bootcampmedia

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.

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    Drupal 7 is no longer supported.

    The root cause of this problem with class loading in systems (both PHP and Drupal) that were not really designed for object-oriented programming. But the class loader in PHP and Drupal has been considerably overhauled in newer versions of PHP and Drupal, and we no longer experience any problems like this.

Production build 0.71.5 2024