Download & Extend

ModuleHandler::setModuleList() should call resetImplementations() in order to avoid edge cases

Project:Drupal core
Version:8.x-dev
Component:base system
Category:bug report
Priority:major
Assigned:Unassigned
Status:closed (fixed)
Issue tags:VDC

Issue Summary

There have been edge cases (for example when running the installer) on which the hookInfo in the module handler was outdated, but the moduleList was updated.

One possible call route is install_finished -> module_set_weight ... drupal_flash_all_caches() -> call some hook,
see #1806334: Convert the node listing at /node to Views for one problem caused by that.

Let's just call resetImplementations once we set new modules.

Comments

#1

Status:active» needs review

This is not a 100% bugfix yet, as for example there are no tests, which proove something is not working.

Additional CachedModuleHandler also plays a certain role in the game.

AttachmentSizeStatusTest resultOperations
drupal-1929656-1.patch3.82 KBIdleFAILED: [[SimpleTest]]: [MySQL] 52,406 pass(es), 1 fail(s), and 0 exception(s).View details

#2

Hm. I think I did exactly this change for another issue already.

Oh yeah, #1911178-33: Remove hook_exit()

#3

Or in other words, the main change here is the one from #1766036-44: ♪♫ Question the sun ♥, the moon, and the stars ♫♪ [Test that stuff.]

This change makes absolutely sense to me, so +1.

+++ b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleApiTest.php
@@ -97,11 +97,15 @@ function testModuleImplements() {
+    // Warm up the module handler, so ensure that the internal caches are
+    // cleared when setting the module list.
+    $module_handler = drupal_container()->get('module_handler');
+    $module_handler->invokeAll('test');

That's the only part that doesn't make sense to me.

The comment apparently tries to help, but I do not understand why that is needed.

#4

I guess it is to call getHookInfo() and fill up the variable for first time?

#5

Status:needs review» needs work

The last submitted patch, drupal-1929656-1.patch, failed testing.

#6

@rootawtc

Yeah this was exactly my intention, but yeah as wrote above, it doesn't really work as expected.

#7

Status:needs work» needs review

#1: drupal-1929656-1.patch queued for re-testing.

#8

Priority:normal» major

This is blocking a major, so it is also major.

#9

Status:needs review» needs work

The last submitted patch, drupal-1929656-1.patch, failed testing.

#10

Issue tags:+Needs tests

For the failure see #1911178-18: Remove hook_exit()

Basically doing

-    $this->assertLogMessage('system', "%module module disabled.", array('%module' => $module), WATCHDOG_INFO);
+    if ($module != 'dblog') {
+      $this->assertLogMessage('system', "%module module disabled.", array('%module' => $module), WATCHDOG_INFO);
+    }

would turn this green

#11

Issue tags:-Needs tests

It seems to be that this problem can only appear when we don't use the cached module handler, so it maybe is time for a separate unit test case,
as this specific detail could be tested without a full bootstrapped drupal/

AttachmentSizeStatusTest resultOperations
drupal-1929656-11.patch5.72 KBIdlePASSED: [[SimpleTest]]: [MySQL] 52,293 pass(es).View details
interdiff.txt1.89 KBIgnored: Check issue status.NoneNone

#12

Issue tags:+Needs tests

Add tag back.

#13

Status:needs work» needs review

#14

Issue tags:-Needs tests

I do not think that this needs any further tests. These tests would essentially try to assert that a previously contained bug no longer exists.

The test failure for dblog.module's hook_watchdog() implementation in #1 only appears, because the current procedure of module_disable() is bogus — HEAD clears the hook implementations too late, which means that watchdog() is invoked with the old list of hook implementations (which include dblog.module, even though it was just disabled).

In other words, all we could test here is that a hook implementation is first found, and no longer found after calling setModuleList() to remove that module.

But that's essentially what the test changes I outlined in #3 are doing: ->invokeAll() is called to prime the hook implementation cache, so as to verify that the subsequent module_enable() also clears the hook implementation cache, whereas module_enable() only calls setModuleList().

Consequently, I think this patch is RTBC.

However, could we quickly improve the inline comment for #3? It doesn't really state and clarify what I just explained above.

#15

I agree that module_enable is covered by this change, but setModuleList is not called only in module_enable right?
That said, this covers most cases and this is major, so i am fine with rtbc

#16

@sun
Do you mean something like that? To be honest I'm still not convinced 100% that this test works as expected but I trust you 100%.

AttachmentSizeStatusTest resultOperations
drupal-1929656-16.patch5.66 KBIdleFAILED: [[SimpleTest]]: [MySQL] Setup environment: Test cancelled by admin prior to completion.View details
interdiff.txt844 bytesIgnored: Check issue status.NoneNone

#17

  // Prime ModuleHandler's hook implementation cache by invoking a
  // random hook name. The subsequent module_enable() below will only
  // call into setModuleList(), but will not explicitly reset the
  // hook implementation cache, as that is expected to happen
  // implicitly by setting the module list. This verifies that the
  // hook implementation cache is cleared whenever setModuleList() is
  // called.
  $module_handler = yada.

#18

Oh that's way better.

AttachmentSizeStatusTest resultOperations
drupal-1929656-18.patch6.02 KBIdlePASSED: [[SimpleTest]]: [MySQL] 52,311 pass(es).View details
interdiff.txt1.13 KBIgnored: Check issue status.NoneNone

#19

Status:needs review» reviewed & tested by the community

Thank you! :)

#20

Status:reviewed & tested by the community» needs work

That special-casing of dblog looks a bit strange, but I guess we were already previously doing that elsewhere in the function.

Unfortunately, no longer applies. :(

#21

Status:needs work» fixed

And by that I mean, committed and pushed to 8.x. :P

Hopefully that worked.. I'm about to be offline for a few hours, but I'll check in again before I hit the sack.

#22

This was (I think) to help with the view for /node, but the debug messages are still there on install #1806334-157: Convert the node listing at /node to Views

#23

Status:fixed» closed (fixed)

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