Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In module.inc system_list returns the results of array_keys() which means that the resulting value is an integer-keyed array. This causes a problem because module_exists() checks to see if the key with the module_name exists and incorrectly reports that a module is not enabled even when it is otherwise available in the boot phase.
Comments
Comment #1
jbrauer CreditAttribution: jbrauer commentedComment #2
douggreen CreditAttribution: douggreen commentedHere's the patch. We can't use drupal_map_assoc() here because this is called before it's loaded.
Comment #3
David_Rothstein CreditAttribution: David_Rothstein commentedComment #5
Fabianx CreditAttribution: Fabianx commentedJust a quick re-roll ...
Comment #7
douggreen CreditAttribution: douggreen commentedThis should fix the test failures about array_combine. It uses similar code that already exists in module_list().
Comment #8
douggreen CreditAttribution: douggreen commentedComment #9
Fabianx CreditAttribution: Fabianx commentedCan we use the extended comment from #5, please?
Comment #10
douggreen CreditAttribution: douggreen commentedI switched to this comment because it was already in core. I don't care. I thought this comment was just as descriptive and one line shorter. If you feel strongly, please re-roll.
Comment #11
Fabianx CreditAttribution: Fabianx commentedNope, not strongly:
RTBC, looks great!
Do we need a test for this given the code violates what the doxy says?
Comment #12
David_Rothstein CreditAttribution: David_Rothstein commentedHm, well if module_exists() essentially doesn't work at all during the bootstrap phase, that sounds like it would be worth having a test for... It would be a pretty simple test to write, too, I think?
Comment #13
donaldinou CreditAttribution: donaldinou as a volunteer commentedIf the problem is that system_list could return numeric we can patch the module_list function. Because module_list expresively say that it return
An associative array whose keys and values are the names of the modules in the list.
So return a numeric key is definetively a "bug".
Comment #14
stefan.r CreditAttribution: stefan.r commentedComment #15
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commented@donaldinou As was mentioned in #2496587-4: module_exists() always returns FALSE during early bootstrap, I agree that it is better to fix this in
system_list()
, because that code is one level down, so the bug will be fixed directly where it originated. Themodule_list()
itself is not a problem, the problem is in values it gets fromsystem_list()
. And the documentation clearly states, thatsystem_list()
:I have rerolled the patch from #7 and added a simple test, which should fail without the patch. The patch itself (#7) is unchanged. If the test results will be OK, hopefully this can be RTBC again.
Comment #17
mcdruidThis looks great, thanks for adding the test!
Comment #19
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedThanks everyone!