Problem/Motivation
Coming from #3120096-135: Support contrib database driver directories in a fixed location in a module.
This happens if a database driver is provided by a module, since this bit introduced by the parent
+++ b/core/lib/Drupal/Core/Database/Database.php
@@ -457,18 +462,130 @@ public static function convertDbUrlToConnectionInfo($url, $root) {
- // Discover if the URL has a valid driver scheme. Try with custom drivers
- // first, since those can override/extend the core ones.
- $connection_class = $custom_connection_class = "Drupal\\Driver\\Database\\{$driver}\\Connection";
- if (!class_exists($connection_class)) {
- // If the URL is not relative to a custom driver, try with core ones.
- $connection_class = "Drupal\\Core\\Database\\Driver\\{$driver}\\Connection";
+ // Determine if the database driver is provided by a module.
+ $module = NULL;
+ $connection_class = NULL;
+ $url_components = parse_url($url);
+ if (isset($url_components['query'])) {
+ parse_str($url_components['query'], $query);
+ if ($query['module']) {
+ $module = $query['module'];
+ // Set up an additional autoloader. We don't use the main autoloader as
+ // this method can be called before Drupal is installed and is never
+ // called during regular runtime.
+ $namespace = "Drupal\\$module\\Driver\\Database\\$driver";
+ $psr4_base_directory = Database::findDriverAutoloadDirectory($namespace, $root, TRUE);
+ $additional_class_loader = new ClassLoader();
+ $additional_class_loader->addPsr4($namespace . '\\', $psr4_base_directory);
+ $additional_class_loader->register(TRUE);
+ $connection_class = $custom_connection_class = $namespace . '\\Connection';
+ }
+ }
when the $root is null will pass that in ::findDriverAutoloadDirectory which in turn will try to create an instance of ExtensionDiscovery - but the constructor of that method requires $root to be a string, non-nullable.
This is not failing on DrupalCI because you need to run the Cache group of test with a module-based contrib db driver.
Proposed resolution
The fix is to ensure that the app root is setup before calling the chain of methods.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #2
mondrakeComment #3
mondrakeComment #4
mondrakeComment #5
mondrakeComment #6
mondrake#3 is not enough, since it still fails with
Comment #7
mondrakeComment #8
mondrakeComment #9
mondrake#7 is not good, either:
Comment #10
mondrakeComment #11
mondrake#10 still not good, because even trying to format the error message with the driver name ends up in 'class not found' error.
Comment #12
mondrakeComment #13
alexpottThis test is done in a really really odd way. I think it deserves a rewrite. The way it is changing the database namespace is entirely unsupported.
Comment #14
mondrake#12 works, for me.
Comment #15
mondrakeComment #16
alexpottAnother option here is to check for core drivers. In order to use this test contrib drivers already have to extend the test so this all feels very complex.
Comment #17
daffie commentedI think that we should not do the patch from comment #12. As far as I can see the test will be skipped for any contrib driver. And for me this is wrong. This is testing a major bug fix with a single test class. For me any contrib driver should pass this test. A contrib driver should extend this test. Add there own version of the helper module "database_statement_monitoring_test" and override the method
getDatabaseConnectionInfo().Or we can rewrite this test as @alexpott is suggesting.
Comment #18
daffie commentedAdding link to the major bug #2966607: Invalidating 'node_list' and other broad cache tags early in a transaction severely increases lock wait time and probability of deadlock.
Comment #19
alexpottGiven #17 can we design the test so that it passes for core and fails for a contrib driver unless it finds the necessary class. That way we achieve the desired outcome of making it easier for contrib drivers to run this test and know that they should have it passing.
Comment #20
mondrakeRerolled.
Comment #21
daffie commented@mondrake: In #3124354-11: Remove unnecessary classes from the database drivers @alexpott made a suggestion how to improve this test. Can you take a look at it and see if it works for your contrib driver?
Comment #22
mondrake@daffie maybe, yes. #20 is just there to have a patch to load in local testing. Once #3124354: Remove unnecessary classes from the database drivers will be green I'll try to switch to that patch.
Comment #23
mondrake#3124354: Remove unnecessary classes from the database drivers got committed, but that did not solve the issue here.
Comment #24
daffie commentedI think that this issue needs #3129043: Move core database drivers to modules of their own to land. The patch makes a code change to EndOfTransactionQueriesTest:
For the test to work for contrib database drivers, the contrib drivers need to add their own fake database_statement_monitoring_test driver in the module part of the driver. See #3128699: Testing issue for pgsql_fallback.
Comment #25
mondrakeThanks for feedback @daffie. Postponing then.
Comment #26
beakerboyComment #27
daffie commentedClosing this issue as it is a duplicate of #3152003: EndOfTransactionQueriesTest does not include bootstrap.inc early enough for contrib database drivers.
Comment #28
mondrakeThanks @daffie @Beakerboy, unfortunately #3152003: EndOfTransactionQueriesTest does not include bootstrap.inc early enough for contrib database drivers did not fix the issue here, nor I expect #3151118: Include bootstrap.inc using composer will.
The problem is with
parent::setUp();really regardless of where it is positioned, because if the db driver has not registered a\Drupal\database_statement_monitoring_test\{driver}\Connectionclass, we get the following failure:Comment #34
mondrakeThis was fixed by #3316923: Sort out more driver specific database kernel tests.