Problem/Motivation

Trash module cannot be installed at the same time as node on Drupal 11.x. This suggests the fix implemented in #3494212: Modules that provide fields for entities of other modules can't be installed was only a partial fix.

Steps to reproduce

Run \Drupal\Tests\trash\Functional\TrashNodeTest::testTrashAndRestoreNode on 11.x and see the error:

1) Drupal\Tests\trash\Functional\TrashNodeTest::testTrashAndRestoreNode
Drupal\Core\Entity\EntityStorageException: Exception thrown while performing a schema update. Cannot add field 'node_field_data.deleted': table doesn't exist.

Proposed resolution

Install all modules entity schema prior to installing configuration.

Remaining tasks

User interface changes

None

Introduced terminology

N/a

API changes

None

Data model changes

None

Release notes snippet

N/a

Issue fork drupal-3496558

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alexpott created an issue. See original summary.

alexpott’s picture

This is happening because Trash has a config listener \Drupal\trash\EventSubscriber\TrashConfigSubscriber::onSave() that is triggered when trash.settings is saved an adds fields to any enabled entity types. At this point the node module has been enabled but is yet to be processed by the loop that processes the entity installations and simple config in config/install.

A core fix could be

  • to prioritise modules that declare entity types over modules that don't - this feels hard and fragile.
  • Install entity definitions for all modules and then simple config - not sure of the impact

Or we could move this to the trash module and use the container_rebuild_required flag.

alexpott’s picture

Status: Active » Needs review
alexpott’s picture

This feels amazing but this has broken \Drupal\FunctionalJavascriptTests\Ajax\AjaxTest::testGlobalEvents() - I wonder how this has broken that and how that test is the only test of something in the module installer!!!!

alexpott’s picture

#5 turned out to be unrelated - it was caused by a recent commit to HEAD - see #3492582: Replace some of obj && obj.prop with optional chaining

alexpott’s picture

Issue tags: +Needs tests

I've discussed this with @amateescu and we both think that this change is likely to make the move to multi-module install easier as it means that database schema will be correct before any modules start installing config.

alexpott’s picture

Issue summary: View changes
alexpott’s picture

alexpott’s picture

Note that the trash module is now fixed due to #3496091: Improve the way we enable Trash support by default for nodes being committed.

smustgrave’s picture

What’s a good way to test this one? Or just follow steps to reproduce

smustgrave’s picture

Status: Needs review » Needs work

NW for the tests, but admit I'm not super familiar with the trash module (didn't know of it will this ticket) but wonder if whatever it was doing could be copied in a core test module?

godotislate made their first commit to this issue’s fork.

godotislate’s picture

Title: Trash and node modules cannot be installed at the same time on 11.x » Install entity definitions for all modules in batch install before simple config
Status: Needs work » Needs review
Issue tags: -Needs tests

Added a test. The test works similarly to how trash does: there is a new test module with event subscriber for saving simple config provided by the module. When node and the test module are installed at the same time, the subscriber sets a flag in keyvalue for whether the node entity field table exists at the time of config save.