Fixed
Project:
Drupal core
Version:
12.0.x-dev
Component:
other
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
30 Sep 2024 at 14:26 UTC
Updated:
17 Oct 2026 at 17:16 UTC
Jump to comment: Most recent
Added several phpcs:ignore lines in DriverSpecificTransactionTestBase in order for tests to pass. With a variable for the return the tests fail. I can't say that I understand why.
From @quietone in #3477205: Use DrupalPractice.CodeAnalysis.VariableAnalysis in core/tests
N/A
TBD - need to determine why they are needed to pass
Document why variables are/aren't needed
if they can be removed fix it and remove phpcs ignore
N/A
N/A
N/A
N/A
N/A
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:
Comments
Comment #2
smustgrave commentedComment #3
mondrakeWhat's the sniff doing? Checking if variable is unused after having been declared?
If that's the case, then the problem is clear - transactions are instantiated and then only committed while destructing a variable that is going out of scope. So you declare it, but then you just exit the method to get it committed - no explicit action on the variable. You may want to get it descoped explicitly via
unset(), but then some of the tests would no longer make sense.This current approach already created a lot of problems and this is another one coming. I think everyone agrees we should not do database operations while destructing a variable; #3406985: Convert all transactions in core to use explicit ::commitOrRelease() is the next step to move away from that.
Comment #5
luissousa21 commentedI ran the experiment this issue asks for, against mysql.
The assignment is what keeps the transaction open. A
Transactioncommits or releases itself when it is destructed, so the variable holds it alive until the test method ends. Call the helper without assigning the result and the object is destroyed immediately, ending the transaction or savepoint there and then.Dropping the assignment in
testRollbackRootWithActiveSavepoint()so it reads$this->createFirstSavepointTransaction();makes the test fail:Failed asserting that exception of type "Drupal\Core\Database\TransactionOutOfOrderException" is thrown.That is the mechanism @mondrake describes in #3: once the savepoint has been released, rolling back the root is no longer out of order, so nothing is raised. With the assignment in place the same test passes with 12 assertions.
The issue asks whether they can be removed and the ignores dropped. They cannot, as these tests are currently written, which leaves documenting them.
What I would suggest:
createRootTransaction()andcreateFirstSavepointTransaction(), since that is where a reader meets the return value.I tried the inline
phpcs:ignore ... -- reasonform first. It suppresses correctly, but it pushes those lines well past 80 characters and core does not use that syntax anywhere, so a comment line above looked like the better fit.Two things to watch if someone picks this up.
phpcs:ignoreapplies to the line that follows it, so a comment added above must not detach the suppression. It does not; the sniff still reports the file clean. And to confirm that clean result was real rather than the sniff skipping the file, removing a single suppression produces exactly one warning.Happy to open an MR along those lines if the direction looks right. The wider point @mondrake raises in #3, whether these tests should stop depending on destruct-time behaviour at all now that #3406985 has landed, is a bigger call than this issue and I would rather not pre-empt it.
Comment #8
luissousa21 commentedComment #9
smustgrave commentedSorry the AI verboseness is a little over the top on this one. Could that be rewritten by a human please.
Comment #10
zeeshan_khan commented@smustgrave Thanks for calling that out. Fair point, that was AI-drafted and I posted it without trimming it. Shortened the comments and just pushed. Good lesson for me, I'll write these myself from now on instead of posting AI output straight into core issues. Appreciate you taking the time to flag it.
Many Thanks
Comment #11
luissousa21 commentedComment #12
franckylfs commentedIt took us a while to wrap our heads (we were 3 with alberto56 and ulysse33) around it (in a Drupal meetup), but the comments make sense to us.
Comment #13
longwaveCommitted and pushed 4c0717bbd4f to main and 21f8590d92d to 12.0.x. Thanks!