Problem/Motivation
#3129043: Move core database drivers to modules of their own moved core's database drivers into modules. As part of that, it added backwards compatibility in Settings::initialize() to autoload from those module directories. However, it added that autoloading too aggressively, because it's also doing it for drivers with the namespace Drupal\Driver\..., if the driver is one of "mysql", "pgsql", or "sqlite".
https://www.drupal.org/project/mysql56 is an example of a project that provides a Drupal\Driver\... implementation of a "mysql" driver. This project works in Drupal 9.3, but fails in Drupal 9.4 due to incorrect autoloading being added for this project's namespace into the core/modules/mysql/... directory.
Steps to reproduce
Proposed resolution
Change the BC autoloading to only apply for the correct (i.e., "Drupal\{$driver}") namespace.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | diff.txt | 590 bytes | effulgentsia |
| #10 | 3284502-10.0.x.patch | 8.02 KB | effulgentsia |
| #3 | 3284502-3-test-only.patch | 3.25 KB | effulgentsia |
| #2 | dbdriver-less-aggressive-autoload.patch | 2.18 KB | effulgentsia |
Comments
Comment #2
effulgentsia commentedComment #3
effulgentsia commentedHere's a test-only patch that proves the bug, and a patch that combines the test with the fix in #2.
Comment #5
longwaveI saw this yesterday and thought about asking for test coverage, but didn't think it was going to be easy - but your neat unit test proves me wrong!
Comment #6
alexpottThe previous switch construction avoids unnecessary loops if you don't have autoload set. Let's go back to that.
Comment #7
alexpottWe also need a patch for 10.0.x because this code is still on that branch.
Comment #8
alexpottAs per @xjm this is at least a major regression. It feels critical if you are using https://www.drupal.org/project/mysql56 as you will not be able to update to 9.4.
Comment #9
effulgentsia commentedThis changes the loop to a switch/case per #6. Because that creates a little code duplication, I also duplicated the test cases to make sure pgsql and sqlite are similarly tested.
Comment #10
effulgentsia commentedHere's the 10.0.x patch as well. It only differs by context lines, as shown by the diff.
Comment #11
effulgentsia commentedYeah, I tagged it as a soft blocker, because the workaround would be for sites using that module to fill in the 'autoload' key in their settings.php, but it would be annoying for each site to have to do that (and otherwise unnecessary since that module already adds itself to the autoloader separately), so getting this committed to 9.4.0 would be much appreciated!
Comment #12
daffie commentedAll the code changes look good to me.
Testing has been added.
The points of @alexpott have been addressed.
For me it is RTBC.
Comment #13
alexpottCommitted 85120a6 and pushed to 10.0.x. Thanks!
Committed and pushed 145af574f3 to 9.5.x and 5a6aa7be7d to 9.4.x. Thanks!
Comment #17
alexpottOpened #3284970: Reduce complexity in \Drupal\Core\Site\Settings::initialize as a quick follow after thinking about the changes here some more.