Problem/Motivation

The locale module tries to add extra info to the node entity in locale_entity_info_alter(), even when the node entity is not there yet.

Install for example https://www.drupal.org/project/paddle, enable the Simpletest Drupal module and try to run a test which installs the paddle profile.
You can also achieve the failure by adding a bunch of modules to a custom profile which have locale as dependency. The locale module will be installed before the node module and the exceptions will happen.

You will get the following:
Exception Notice field.crud.inc 92 field_create_field()
Undefined index: entity keys
Exception Warning field.crud.inc 92 field_create_field()
in_array() expects parameter 2 to be array, null given
Exception Notice field.crud.inc 92 field_create_field()
Undefined index: entity keys
Exception Warning field.crud.inc 92 field_create_field()
in_array() expects parameter 2 to be array, null given
Exception Notice field.crud.inc 92 field_create_field()
Undefined index: entity keys
Exception Warning field.crud.inc 92 field_create_field()
in_array() expects parameter 2 to be array, null given
Exception Notice field.crud.inc 92 field_create_field()
Undefined index: entity keys
Exception Warning field.crud.inc 92 field_create_field()
in_array() expects parameter 2 to be array, null given
Exception Notice module.inc 449 module_enable()
Trying to get property of non-object

Proposed resolution
Wrap the alteration in an if-statement which checks if the node entity exists.

User interface changes
None

API changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

iSoLate created an issue. See original summary.

iSoLate’s picture

Title: Define node module dependency in locale.info » locale_entity_info_alter() causes notices
iSoLate’s picture

iSoLate’s picture

Status: Active » Needs review
iSoLate’s picture

Issue summary: View changes
michel.g’s picture

Status: Needs review » Reviewed & tested by the community

I have tested the patch locally with the paddle profile which you linked and it does indeed fix the issue.
Also kudos for using the same method which has been used to solve that issue with the comment module.

iSoLate’s picture

Assigned: iSoLate » Unassigned
David_Rothstein’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

The Node module is a required module, so the Locale module should be able to depend on it. I think we need to get to the root cause of this bug.

Install for example https://www.drupal.org/project/paddle, enable the Simpletest Drupal module and try to run a test which installs the paddle profile.
You can also achieve the failure by adding a bunch of modules to a custom profile which have locale as dependency. The locale module will be installed before the node module and the exceptions will happen.

I couldn't get very far with the Paddle profile because the latest version has other errors when you try to install it (e.g. it seems to be trying to enable modules that don't exist in the codebase). But when I looked at the order in which Drupal was trying to install that profile's modules, as well as trying it with a separate profile as described above, I couldn't see any problem. Since the Node module is a required module and https://api.drupal.org/api/drupal/includes!install.core.inc/function/ins... always tries to install required modules first, it always installs Node before Locale.

Any more details on how to reproduce this?

David_Rothstein’s picture

This issue summary here does specifically say that the problem happens when running tests, so I guess it's worth mentioning that I couldn't figure out how to reproduce it there either. When a profile is installed in a test, it does use a code path that's different from the above, but it does it via https://api.drupal.org/api/drupal/modules%21simpletest%21drupal_web_test... which calls https://api.drupal.org/api/drupal/includes%21install.inc/function/instal... which looks like it always installs required modules before non-required ones also, so again, the result is the same and I couldn't figure out how to get the Locale module installed before the Node module.