When viewing the module list at /admin/modules the checkboxes are disabled if any of the dependencies of that module are not present. At core 8.7 this worked fine. But at 8.8 if a module depends on a core module with a given version, the check always fails. The problem is due to interaction with the contrib module git_deploy, however it is core code which actually causes the problem.

An example is Views Bulk Operations, which depends on Views >=8.4 (ie core 8.4 and up). This test passed OK at Core 8.7 but at Core 8.8 the test fails and VBO cannot be installed. This is due to a quirk in the programming in core/modules/system/src/Form/ModulesListForm.php, where the string \Drupal::CORE_COMPATIBILITY . '-' i.e. '8.x-' in this case, is removed from the module version. The intention is to convert contrib module versions, say '8.x-1.2' into '1.2' for comparison. When the module is a core module the version at core 8.7 was 8.7.x-dev and this gets passed through and all works fine.

But at Core 8.8 we have the unintended side-effect that removing '8.x-' also matches the middle of the core version '8.8.x-dev' which is not the intented change. The value passed on is therefore '8.dev' which fails to satisfy the constraint test >=8.4. Without git_deploy the version of the core module is 8.8.n-dev (taken from \Drupal::VERSION) where n is a number, say 8.8.3-dev, and this works fine. But git_deploy changes the patch digit to x, so that the version is 8.8.x-dev and this is where the str_replace incorrectly removes the middle '8.x-'

To see this bug in action, create a drupal 8.8 dev site, install the git_deploy contrib module, then try ti download Views Bulk Operations and try to enable it.

Update for D9 and D10

The problem is not immediately apparent at the current dev core versions 9.5.x and 10.1.x because it only occurs when the minor version is 8. It was a problem at core 8.8.x and will be a problem again when Drupal 9 reaches 9.8, and likewise with 10.8.

The code in question has now moved to core/lib/Drupal/Core/Extension/ModuleDependencyMessageTrait.php but it still contains the same problem.

Proposed Solution

Change the plain str_replace() to a preg_replace() to enforce that the string replacement is only matched at the start of the core version, not anywhere within it.

Issue fork drupal-3086845

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jonathan1055 created an issue. See original summary.

jonathan1055’s picture

Here are screen shots showing VBO and the failed constraint test. In the workings in the I.S. above, I had the Git Deploy module enabled, and that rendered the core version as '8.8.x-dev'. Without Git Deploy, the core version is 8.8.0-dev. But in both cases, the constraint test fails.

This same behaviour is also seen when a contrib module has a direct core version constraint in its .info.yml file, such as

dependencies:
  - drupal:system (>= 8.5)

Module maintainers have been encouraged to add this type of constraint when their module is only compatible above a certain version of core. However, now at 8.8.x-dev this constraint fails.

I think the code in core/modules/system/src/Form/ModulesListForm.php, function buildRow should be able to be adjusted to fix this.

jonathan1055’s picture

Project: Drupal core » Git Deploy
Version: 8.8.x-dev » 8.x-2.x-dev
Component: extension system » Code

Actually this does seem to be caused by Git Deploy, inadvertantly. I do not know how I got that screen grab showing the failure when Git Deploy is not enabled, as I cannot now recreate that. At Core 8.8-dev without Git Deploy the core module versions are 8.8.0-dev and the attempted removal of '8.x-' does nothing. It is only when Git Deploy is active, and the core version is changed to 8.8.x-dev do we get this nasty side-effect of the dependency's version being reduced to 8.dev

Moving into the Git Deploy queue for discussion, however, it is core code in core/modules/system/src/Form/ModulesListForm.php which does the str_replace which causes the probelm. The if(!$dependency_object->isCompatible(str_replace(\Drupal::CORE_COMPATIBILITY . '-', '', $modules[$dependency]->info['version'])) is dubious and would appear to be dangerous, as the module versions be processed are both contrib and core. There must be a better way to do this. Maybe version_compare will cope without the str_replace being needed?

jonathan1055’s picture

Title: Module constraint checks fail for core 8.8.x-dev » Module constraint checks fail incorrectly due to str_replace
Project: Git Deploy » Drupal core
Version: 8.x-2.x-dev » 9.1.x-dev
Component: Code » install system
Status: Active » Needs review
FileSize
1.83 KB
106.18 KB

Moving this back to the Core issue queue, as it is core code which needs to be adjusted. The cause of the problem is doing a blind str_replace to remove \Drupal::CORE_COMPATIBILITY- from the version string. What was actually intended is to remove it only when it starts the string, not remove from anywhere within the string. This can easily be achieved by changing to use a simple preg_replace.

The incorrect constraint results can also be seen when trying to run update.php. Attached is an example when Views Bulk Operations was installed, but now fails the constraint check. Core 8.8 is installed and VBO needs >= 8.4 but it still fails.

The attached patch makes the required change from str_replace to preg_replace in modulesListForm.php (for the listing page) and install.php (for the update.php page)

jonathan1055’s picture

Re-rolled following the moving of the version checking into the new ModuleDependencyMessageTrait in commit in #310 on #474684-310: Allow themes to declare dependencies on modules

This change is still relevent and should still be made. It is tighter programming, and reduces the possible chance of future problems.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
162 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

DanielVeza’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative

The code in question in ModuleDependencyMessageTrait has changed in the last three years since this issue was raised. Is this still an issue? Can we get some steps to reproduce?

jonathan1055’s picture

Issue summary: View changes

I've updated the IS. It still is a problem, but will not be apparent until we get to core version 9.8.x. I will upload a new patch because ModuleDependencyMessageTrait has been moved from core/modules/system/src (in 9.1) to core/lib/Drupal/Core/Extension (in 9.5 and 10.1)

Using git_deploy I can simulate the core version being moved on to 9.8 and can then reproduce the problem. I was also looking at adding a test to the 'system' module to demonstrate what happens when the core version is 9.8.x or 10.8.x instead of 9.8.0, 10.8.0 etc.

jonathan1055’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
1.78 KB

New patch for 10.1, which also applies at 9.5

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests, +Needs issue summary update

Hello @jonathan1055 reading the issue summary thanks for the update!

Adding some tasks for "Remaining tasks" section.

This will need a test case to show the problem.

Thanks!

jonathan1055’s picture

Issue summary: View changes
Status: Needs work » Needs review

Thanks @smustgrave
I have created a new test module to simulate the version change required, and added test coverage. The test module can be moved or renamed it required. The initial push to 10.1 mr is only for the test, so it should fail.

Also for speed and reduced resource usage I have temporarily limited the tests to just one class.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests, -Needs issue summary update

Test looks good!

Can you revert the one test change and think I can mark it RTBC.

jonathan1055’s picture

Thanks @smustgrave, will do.

For manual checking, the problem can be seen via UI. Install the new dependency_version_test module (which will require local settings $settings['extension_discovery_scan_tests'] = TRUE;

dependency_version_test

Then try to install the test_module which now requires View >=9.2 but it is greyed out and fails the dependency check
test_module

On question I had was is it OK to hardcode 9.2 and 9.8.x in the test modules? I used 9.x as an example because I am hoping this fix can be back-ported to Drupal 9. We will be hit by the bug in core 9.8.x sooner than we reach 10.8.x.

jonathan1055’s picture

Status: Needs work » Needs review

Branch has a random failure so I've clicked 'do not wait for branch to pass' :-)

jonathan1055’s picture

To answer my own question from #19 about hardcoding 9.2 and 9.8.x in the tests, there are existing tests in Drupal 10 that reference core 8.x etc, and use fixtures set up for Drupal 8, so I think this is fine to have 9.2 and 9.8.x in the new test.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for all the work on this @jonathan1055

larowlan’s picture

Crediting smustgrave for an issue summary update

  • larowlan committed cc05ac89 on 10.0.x
    Issue #3086845 by jonathan1055, smustgrave: Module constraint checks...

  • larowlan committed 1b4abdb0 on 10.1.x
    Issue #3086845 by jonathan1055, smustgrave: Module constraint checks...

  • larowlan committed d9ef1091 on 9.5.x
    Issue #3086845 by jonathan1055, smustgrave: Module constraint checks...
larowlan’s picture

Version: 10.1.x-dev » 9.5.x-dev
Status: Reviewed & tested by the community » Fixed

Committed to 10.1.x and backported to 10.0.x and 9.5.x - thanks!

jonathan1055’s picture

Issue summary: View changes

Thanks @larowlan for the commit and for backporting to 9.5.x
The users of git_deploy (me included) will be grateful for this when we reach 9.8.x

Status: Fixed » Closed (fixed)

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