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.
Problem/Motivation
getDriverCalls calls driver(). There's no need for this. Also, it hardwires Core. There's no need for that either.
Proposed resolution
Grab the namespace from the namespace of the connection class itself. This does not have a lot of performance implication since it only happens once per class per run-tests.sh invocation and never in a normal Drupal 8 install.
Comment | File | Size | Author |
---|---|---|---|
#35 | 2462653-35.patch | 3.85 KB | alexpott |
#35 | 32-35-interdiff.txt | 861 bytes | alexpott |
Comments
Comment #1
dawehnerWhy do we support the Drupal 7 way of doing it, in the first place? Can't we drop that now?
Comment #2
chx CreditAttribution: chx at MongoDB commentedYou can not if you want to support test runs without settings.php . That's where namespace is coming from. Where else would it come from?
Comment #3
dawehnerAlright, so we need it to run tests, maybe we could document it at some point
Comment #4
chx CreditAttribution: chx at MongoDB commentedActually... Connection is abstract and so the driver must extend and so we have the namespace at hand. I adjusted the comment as well.
Comment #6
dawehnerLooks great for me. Thank you for adding a bit more explanation.
I think we should get some feedback from crell.
Comment #7
chx CreditAttribution: chx at MongoDB commentedYes, that was my idea too and I pinged him earlier today on IRC already although the issue definitely didn't bloom into this nice reflection solution yet.
Comment #9
chx CreditAttribution: chx at MongoDB commentedThis is why I shouldn't be patching without phpstorm.
Comment #11
Crell CreditAttribution: Crell at Palantir.net commentedI *think* this is what we're talking about; the new code for D8 should handle any autoloadable class. It's the D7 code path that doesn't work for non-core libs, which I think it only used for upgrades, no? I don't know how testbot gets into this...
Comment #12
chx CreditAttribution: chx commented> I don't know how testbot gets into this
If you run
run-tests.sh --dburl
then simpletest_script_setup_database creates a connection definition that doesn't (can not) contain the namespace so this codepath is hit. Check the bot fail above. It shows the code is hit.Comment #14
chx CreditAttribution: chx at MongoDB commentedWell, the connection test needs to change.
Comment #15
chx CreditAttribution: chx at MongoDB commentedAnd yes, this is rapidly heading to where driver() is not used at all but let's kill the last usage in the next patch. It'll look like this:
Edit: the mongodb driver now has a driver name but Fake doesn't and that's right and Fake is in core.
Comment #16
Fabianx CreditAttribution: Fabianx for Drupal Association commentedSo what is missing? Can this be RTBCed? It looks good to me ...
Comment #17
chx CreditAttribution: chx at MongoDB commentedFiled #2463337: Investigate the removal of namespace from connectionoptions for possible further cleanup.
Comment #18
Crell CreditAttribution: Crell at Palantir.net commentedWith that follow up filed, this looks good.
Comment #19
alexpottAny reason why we don't avoid reflection and just do substr(get_called_class(), 0, strrpos(get_called_class(), "\\"))
Can we set the $this->connectionOptions['namespace'] so we don't have to do the reflection multiple times for different classes?
Comment #20
mgiffordUnassigning stale issue. Hopefully someone else will pursue this.
Comment #22
daffie CreditAttribution: daffie commentedI have changed the patch so that the reflection is not run multiple times.
As for:
I have no idea.
Comment #23
daffie CreditAttribution: daffie commentedFor the testbot
Comment #26
chx CreditAttribution: chx commentedAny reason why we don't avoid reflection and just do
Because the following:
is way easier to understand...? Self documenting and all that.
Comment #27
daffie CreditAttribution: daffie commentedWith the patch from comment #22, I have tried to make the calling of the ReflextionObject as little as possible by saving the namespace to
$this->connectionOptions['namespace']
. The problem is that the test ConnectionTest::testConnectionOptions() then fails. In that test a second database connection is made. The connection info from both database connections are tested to see if they are identical. If I save the namespace value to$this->connectionOptions['namespace']
they are not identical. So the question of @alexpott:has to be answered with no.
The first question from @alexpott has been answered by @chx in the previous comment.
In comment #18 is this issue set to RTBC by @Crell. So back to RTBC for the patch from comment #14. That patch still applies.
Comment #28
neclimdultestbot sadly disagrees with you :(
Comment #29
neclimdulMy interdiff tools says this is the interdiff between #14 and #22. Its possible and likely the missing file is causing your failures.
Comment #30
daffie CreditAttribution: daffie commented@neclimdul: The patch from comment #14 made by @chx is the patch that is RTBC for @Crell. Not my patch from comment #22. In that patch have I tried to fix the remarks made by @alexpott. Those remarks are not fixable so I have made the patch from comment #14 RTBC again. If the patch from comment #14 made by chx is not RTBC for you, then please change the status of this issue.
Comment #31
daffie CreditAttribution: daffie commentedI made a mistake in my patch in comment #22 by not adding the the database stub. I have tried locally to pass the ConnectionTest with the database stub and I failed. See comment #27 for the explanation why.
Comment #32
alexpottI think we can do less reflection if we do something like the patch attached.
Comment #33
tstoecklerComment #35
alexpottComment #36
daffie CreditAttribution: daffie commentedI am not exactly sure why it passes the ConnectionTest but it does.
It all looks good to me.
It fixed the problem from the issue summary.
The 2 problems from alexpott in comment #19 are addressed. With one being explained by chx in comment #26.
For me it is RTBC.
Comment #37
neclimdulNeat! Thanks guys!
edit: PS: Sorry about my confusion. Thanks for addressing it and improving everything though!
Comment #40
catchCommitted/pushed to 8.2.x and cherry-picked to 8.1.x. Thanks!