Invoking the event ConfigDistroEvents::IMPORT is broken on Drupal 8.6 because ConfigSync::finishBatch() is not called anymore.

This is critical because it breaks config_sync module on Drupal 8.6.

Steps to reproduce:

  • Install Drupal 8.6.x site using core's Standard install profile.
  • Install Configuration Synchronizer and all dependencies, including Configuration Distro.
  • Edit a configuration file provided by one of your installed modules.
  • Visit the "Configuration Update" screen provided by Configuration Distro.

Run updates.

Expected result: the form reloads and shows no available configuration updates.

Actual result: the form reloads showing the same available configuration updates.

Cause: the Configuration Distro event was not triggered on successful import so Configuration Synchronizer did not refresh snapshots.

Comments

klausi created an issue. See original summary.

klausi’s picture

Status: Active » Needs review
StatusFileSize
new3.3 KB

This patch will only work on Drupal 8.6. because ConfigImporterBatch only exists there.

Do you also want to support Druapl 8.5.x in the future?

nedjo’s picture

Thanks for the bug report and the patch.

It would be nice if we could avoid forking the entire ConfigSync::submitForm() method. One alternative would be:

In a new class, extend ConfigImporterBatch, overriding ::finish() as follows:

  /**
   * {@inheritdoc}
   */
  public static function finish($success, $results, $operations) {
    parent::finish($success, $results, $operations);
    if ($success) {
      // Dispatch an event to notify modules about the successful import.
      \Drupal::service('event_dispatcher')->dispatch(ConfigDistroEvents::IMPORT);
    }
  }

Then implement hook_batch_alter() to swap in our class for the batch 'finished' value.

nedjo’s picture

StatusFileSize
new2.73 KB

Here's a patch implementing the approach from #3, and also leaving the pre-8.6 code intact. On my testing this works in 8.6 and in prior versions.

nedjo’s picture

Issue summary: View changes

Filling in details on how to reproduce this bug.

klausi’s picture

Issue tags: +Needs tests

Patch looks good, although I don't like it that invoking this event is now spread out in 3 files. Makes it harder to maintain and reason about.

The only thing missing now is a test case. I know, config_distro does not have test cases yet, but this is the perfect opportunity to start :-)

Not sure I should set this to "needs work" for that?

  • bircher committed cc4fd65 on 8.x-1.x
    Issue #3000886 by klausi, nedjo: Drupal 8.6 compatibility - ConfigSync::...
klausi’s picture

For testing: how would we simulate a config YAML file change in the install folder of a module? Is there some event that we can use in the tests to modify the imported config on the fly?

bircher’s picture

I agree! We need tests quite urgently.

I am also not a fan of having it split in several locations but the class is an internal class of drupal core that we extend. So it is explicitly not an API and our own fault for extending it. Since 8.5 is now supported until next may we should also support it still until then.
Tests are crucial for that too.

That said, core will need an api for this since the patch in #2991683: Move configuration transformation API in \Drupal\Core\Config namespace does essentially the same and has to do some more trickery too. So we can definitely improve this. I committed the patch now so that we can move forward and things are not left broken.

Thanks for reporting and providing patches!

To answer on how to test. I would create a module and set the previous state of the config in the database directly. So the test module in the file system is after the update. So we install the test module, go in and change the snapshot manually as part of the test and then test the expected difference when importing. But that would be a test for config_sync. For config_distro we won't need to test the installed config, just that the filters for config_distro are taken into account and that the import works properly.

klausi’s picture

Status: Needs review » Needs work

Thanks bircher, good idea about the test! I will try to write that for config_sync so that we have a test case there.

Setting to "needs work" here to leave this open for a test in config_distro itself.

klausi’s picture

nedjo’s picture

@bircher

I'm getting continued reports of breakage in Configuration Synchronizer due to this bug.

Ahead of test coverage, okay to post a new release with this fix?

klausi’s picture

Status: Needs work » Fixed

Release was done, test coverage is now in config_sync. If we want to port test coverage to config_distro then that should be done in a new issue I think.

Status: Fixed » Closed (fixed)

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