(1) my test sends an email
(2) some third party module adds an object to the mail object. An example can be found here: #2279849: Store a key, not the actual invite object, in the mail.
(3) TestingMailSystem::mail(), defined in modules/system/system.mail.inc, puts the mail in a variable (drupal_test_email_collector).
(4) In all subsequement page loads, during variable_initialize(), the variables (including the mail which contains the object) are unserialized.
(5) During the unserialization process, we attempt to instantiate the object, wchich might assume that Drupal has reached a bootstrap phase more advanced than it actually is.

For example, while instantiating an invite object (entity), we get

Fatal error: Call to undefined function entity_get_info() in /Applications/MAMP/htdocs/tremblant/sites/all/modules/contrib/entity/includes/entity.inc on line 56
Call Stack
#	Time	Memory	Function	Location
1	0.0004	235840	{main}( )	../index.php:0
2	0.0120	550288	drupal_bootstrap( )	../index.php:20
3	0.0124	569528	_drupal_bootstrap_page_cache( )	../bootstrap.inc:2242
4	0.0126	624544	drupal_bootstrap( )	../bootstrap.inc:2384
5	0.0131	946360	_drupal_bootstrap_variables( )	../bootstrap.inc:2250
6	0.0132	966264	variable_initialize( )	../bootstrap.inc:2486
7	0.0167	1441288	array_map ( )	../bootstrap.inc:920
9	0.0168	1451240	unserialize ( )	../bootstrap.inc:938
10	0.0198	2367752	Entity->__wakeup( )	../bootstrap.inc:938
11	0.0198	2367784	Entity->setUp( )	

I don't know what the best course of action might be, I just wanted to get this off my chest!

Comments

hefox’s picture

Can confirm, happening to me also

hefox’s picture

You can override the mail handler for the test via

    variable_set('mail_system', array('default-system' => 'oaTestingMailSystem'));

then can create a testing mail system

<?php

/**
 * A mail sending implementation that captures sent messages to a variable.
 *
 * This class is for running tests or for development.
 */
class oaTestingMailSystem extends DefaultMailSystem implements MailSystemInterface {
  /**
   * Accept an e-mail message and store it in a variable.
   *
   * @param $message
   *   An e-mail message.
   */
  public function mail(array $message) {
    $captured_emails = variable_get('drupal_test_email_collector', array());
    foreach ($message['params'] as $key => $param) {
      if (is_object($param) && get_class($param) !== 'stdClass') {
        unset($message['params'][$key]);
      }
    }
    $captured_emails[] = $message;
    variable_set('drupal_test_email_collector', $captured_emails);
    return TRUE;
  }
}

that removes an non-stdclass objects.

Can patch core to do this (system.mail.inc class TestingMailSystem), but not sure what is the best thing to do -- remove the offending object like above, cast it to an stdClass?

oliver huynh’s picture

Priority: Normal » Major

I faced a mysterious issue during months and had to flush the cache each time the white screen appeared. The issue is below
"Fatal error: Call to undefined function commerce_line_item_type_get_name() in..."
"Similar errors also"

Until today I did a deep debug and figured out the variable_init try to unserialize drupal_test_email_collector which is an entity. This will raise a fatal error whenever the variables is not cached yet.
To my fix, I had removed that variable (drupal_test_email_collector) via MySQL, and clean bootstrap cache
DELETE FROM `cache_bootstrap` WHERE `cid` = 'variables'
DELETE FROM `variable` WHERE `value` LIKE '%EntityDrupalWrapper%'
however the issue can happen with any variable which is an entity.

Execute this query
SELECT * FROM `variable` WHERE `value` LIKE '%EntityDrupalWrapper%'
to find that variable and you will figure out how to fix that then.

Update: I figured out the "TestingMailSytem" is used in /admin/config/system/mailsystem. To fix this, just change this class to other testing mail class.

ronino’s picture

Casting entities in email parameters to stdClass objects helped me fix the issue:

$params['variables']['message'] = (object) (array) $message;

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.