We're seeing issues with BundleFieldDefinition when using Drush. It seems to happen all of the time - import config, we get this error; update dbs, this error; install/uninstall module, this error:

Fatal error: Cannot use Drupal\entity\BundleFieldDefinition as BundleFieldDefinition because the name is already in use in docroot/modules/contrib/commerce/src/ConfigurableFieldManager.php on line 8
Drush command terminated abnormally due to an unrecoverable error.                                                        [error]
Error: Cannot use Drupal\entity\BundleFieldDefinition as BundleFieldDefinition because the name is already in use in
docroot/modules/contrib/commerce/src/ConfigurableFieldManager.php, line 8

Running drush cr clears the error and usually we can continue, but if we try again later, it reappears. (For example, turn PC off, go home, come back the next day, update site - boom! error.)

Although I saw the error today when I tried to uninstall the Migrate module and its dependencies from our production environment. I ran drush pmu migrate -y, saw this error, cleared the cache as usual, and when I ran the uninstall command again, I saw the error again. I had to uninstall through the UI on the site, which I've never had to do before.

We're currently on Commerce 8.2, upgrading to 8.3 today, so if it's fixed in 8.3 then great, but it's something we've only seen happening since upgrading to 8.2. I did find #2922811: Deprecate BundleFieldDefinition and BundlePluginInterface which sounded related but seems to have been the cause of the issue.

All of the modules on our site are at the latest stable versions and Drupal itself is up-to-date. We run core and module updates every two weeks at the end of our internal sprints.

We see this issue on our local dev environments (has happened across several devs' PCs), but also on Acquia on all three environments (dev, stage and prod). It's impacting on the server right now because they are trying to test something for us but when they run the commands we give them (migration commands) they are blocked by this error.

We are running:

  • PHP 5.6 on Docker locally
  • PHP 5.6 on Acquia
  • Extra Commerce modules: Commerce Order Number, Commerce Braintree, Commerce Google Analytics

We've made a lot of customisations to Commerce itself and I'm happy to provide any details that might be useful.

Comments

Sophie.SK created an issue. See original summary.

bojanz’s picture

Marked #2937169: Cannot use EntityAccessControlHandler; because the name is already in use as a duplicate. Same error, same PHP version, different class.

DrupalCI passes on 5.6, no error reported: https://dispatcher.drupalci.org/job/drupal_contrib/143230/console

The namespace FAQ also clarifies that what we're doing is perfectly legal (importing a class with the same name as the one in the current namespace): http://php.net/manual/en/language.namespaces.faq.php

bojanz’s picture

vanlindholm says on the duplicate issue that switching to PHP7 resolved the issue, which might confirm that we're dealing with a PHP 5.6 specific bug.

czigor tried on his PHP 5.6 install, and was unable to reproduce, so it might be specific to certain patch versions.

  • bojanz committed e7a7ea7 on 8.x-2.x
    Issue #2937039 by bojanz: Cannot use BundleFieldDefinition; the name is...
bojanz’s picture

Status: Active » Fixed

Research showed that the error does indeed happen on some installs. It can vary based on your PHP patch version, and whether you have opcache. The general recommendation is to always use aliases in this case.

Added an alias to ConfigurableFieldManager/ConfigurableFieldManagerInterface.

We can clean this up once we remove the deprecated BundleFieldDefinition, wanted to wait a bit more for that since we only deprecated it 2 months ago, and the last shipping release still uses it.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.