Problem/Motivation

Follow-up to #2655104: List unmet configuration dependencies instead of just failing, introduce a notice caused by array_unique.

Notice: Array to string conversion in Drupal\Core\Config\ConfigInstaller->checkConfigurationToInstall() (line 460 of core/lib/Drupal/Core/Config/ConfigInstaller.php).

	     if (!empty($invalid_default_config)) {
-      throw UnmetDependenciesException::create($name, $invalid_default_config);
+      throw UnmetDependenciesException::create($name, array_unique($missing_dependencies));
     }

Proposed resolution

  1. Remove array_unique. If same dependency is missing in different configurations, display all of them. We shouldn't choose to display only one of them.
  2. Use the SORT_REGULAR flag, but this will display some duplicate dependencies.
  3. Remove array_unique and replace logic in formatConfigObjectList() or before array_unique call and formatConfigObjectList().

Remaining tasks

  • Define the best choice
  • Create patch
  • Create tests
  • Review patch

Comments

GoZ created an issue. See original summary.

goz’s picture

Status: Active » Needs review
StatusFileSize
new1.22 KB

My preferred solution is 1.
Attach a patch for it.

dawehner’s picture

Issue tags: +Needs tests

What about introducing some small test to it?

goz’s picture

Issue summary: View changes

Right, but if i can have feedbacks about 3 proposed solutions (or another) before writing tests

james.williams’s picture

@GoZ I think you're taking the right approach here. Someone else wiser than me might think otherwise, but I agree with you. The array_unique() usage looks to be left over from an early version of the other issue's patch in #2655104-13: List unmet configuration dependencies instead of just failing, which dealt with a flat array of dependencies, but it later changed into a multi-dimensional array which would cause this notice.

goz’s picture

Issue summary: View changes
Status: Needs review » Needs work
goz’s picture

Category: Task » Bug report
Priority: Normal » Major
Status: Needs work » Needs review
StatusFileSize
new5.27 KB
new6.17 KB

Here is two patch, one should failed. It's unique purpose is to show the current code is wrong.

The second patch is the good one with tests + fix.

The last submitted patch, 7: array_unique_notice-2816307-7-TESTS-ONLY-SHOULD-FAIL.patch, failed testing.

goz’s picture

Issue tags: -Needs tests
james.williams’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me and the tests pass/fail as they should - thanks!

catch’s picture

Status: Reviewed & tested by the community » Needs review

Hmm I think I would have gone for option 2 or 3 here to reduce the duplicates. Why not just use SORT_REGULAR to at least have fewer dups?

goz’s picture

Issue summary: View changes
james.williams’s picture

StatusFileSize
new5.05 KB
new870 bytes

Here's a new patch then that uses the sort flag with array_unique(). :-)

goz’s picture

I don't think 2 or 3 are a good solution.

  // At start, with multiple dependencies for 2 different configuration from same dependencies:
  $missing_dependencies = ['config_test.dynamic.other_module_test_with_dependency' => ['config_other_module_config_test', 'config_test.dynamic.dotted.english'], 'config_test.dynamic.yet_another_module_test_with_dependency' => ['config_other_module_config_test', 'config_test.dynamic.dotted.english']]);

  // After array_unique($missing_dependencies, SORT_REGULAR):
  $missing_dependencies = ['config_test.dynamic.other_module_test_with_dependency' => ['config_other_module_config_test', 'config_test.dynamic.dotted.english']]);

Error message should be as exhaustive as possible. With array_unique, we miss information about missing dependencies for config_test.dynamic.yet_another_module_test_with_dependency config (even if they are the sames as config_test.dynamic.other_module_test_with_dependency, we should known this config has missing dependencies to).

I don't see other methods, except grouping by dependencies instead of config to have fewer dups.

Status: Needs review » Needs work

The last submitted patch, 13: array_unique_notice-2816307-13.patch, failed testing.

james.williams’s picture

Sorry patch #13 was rushed -- the change to use the sort flag was implemented, but I didn't change the test, which of course now needs to test for a different message.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jofitz’s picture

Status: Needs work » Needs review
StatusFileSize
new4.79 KB
new1.84 KB

Corrected the test.

claudiu.cristea’s picture

Status: Needs review » Needs work
+++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigInstallTest.php
@@ -202,6 +202,15 @@ public function testDependencyChecking() {
+      $this->assertEqual($e->getExtension(), 'config_install_double_dependency_test');
+      $this->assertEqual($e->getConfigObjects(), ['config_test.dynamic.other_module_test_with_dependency' => ['config_other_module_config_test', 'config_test.dynamic.dotted.english']]);
+      $this->assertEqual($e->getMessage(), 'Configuration objects provided by <em class="placeholder">config_install_double_dependency_test</em> have unmet dependencies: <em class="placeholder">config_test.dynamic.other_module_test_with_dependency (config_other_module_config_test, config_test.dynamic.dotted.english)</em>');

This is new code, we should not use deprecated assert methods: s/assertEqual/assertEquals.

himanshu-dixit’s picture

Status: Needs work » Needs review

IMHO we need to clean full core to remove the deprecated asset methods. There are many places where i saw that there are many places where these assert methods are used.

    \Drupal::service('config.manager')->uninstall('module', 'config_collection_install_test');
    $this->assertEqual(array('entity'), $active_storage->getAllCollectionNames());
    \Drupal::service('config.manager')->uninstall('module', 'config_test');
    $this->assertEqual(array(), $active_storage->getAllCollectionNames()); 

Let's create a follow up for this. What do you think?

james.williams’s picture

Status: Needs review » Needs work

@himanshu-dixit it would need doing at some point, yes, though it needs to be in the right branch to for the BC policy.

@claudiu.cristea Thanks, good spot. Putting back to needs work then.

himanshu-dixit’s picture

Status: Needs work » Needs review
StatusFileSize
new4.79 KB
new1.74 KB

If we are going to fix it for this issue. Here is the patch,

UPDATE: Sorry, didn't noticed #21 was posted before i was submitting the patch.

dawehner’s picture

+++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigInstallTest.php
@@ -202,6 +202,15 @@ public function testDependencyChecking() {
+      $this->assertEquals($e->getExtension(), 'config_install_double_dependency_test');
+      $this->assertEquals($e->getConfigObjects(), ['config_test.dynamic.other_module_test_with_dependency' => ['config_other_module_config_test', 'config_test.dynamic.dotted.english']]);
+      $this->assertEquals($e->getMessage(), 'Configuration objects provided by <em class="placeholder">config_install_double_dependency_test</em> have unmet dependencies: <em class="placeholder">config_test.dynamic.other_module_test_with_dependency (config_other_module_config_test, config_test.dynamic.dotted.english)</em>');

Note: assertEquals should get the expected value as first parameter.

himanshu-dixit’s picture

StatusFileSize
new1.74 KB
new4.79 KB

@dawehner Thanks for catching this, i forgot about it KernelTestBase. Here is the new patch, do you think this can get RTBC?

claudiu.cristea’s picture

Status: Needs review » Reviewed & tested by the community

RTBC if passes.

  • catch committed 25f990b on 8.4.x
    Issue #2816307 by GoZ, himanshu-dixit, james.williams, Jo Fitzgerald,...

  • catch committed 03afa04 on 8.3.x
    Issue #2816307 by GoZ, himanshu-dixit, james.williams, Jo Fitzgerald,...
catch’s picture

Version: 8.4.x-dev » 8.3.x-dev
Status: Reviewed & tested by the community » Fixed
Issue tags: -String change in 8.3.0

Committed/pushed to 8.4.x and cherry-picked to 8.3.x, thanks! Untagging as string change since there's no string change here.

himanshu-dixit’s picture

Attribution Added

Status: Fixed » Closed (fixed)

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