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.
The file core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php uses a duplicate placeholder in the expression
->expression('timestamp', 'CASE WHEN timestamp > :timestamp THEN timestamp ELSE :timestamp END', [
':timestamp' => $timestamp,
])
This is contrary to the Drupal stipulation that:
A query may have any number of placeholders, but all must have unique names even if they have the same value.
Comment | File | Size | Author |
---|---|---|---|
#15 | 3128761-15.patch | 1.21 KB | Beakerboy |
Comments
Comment #2
BeakerboyPatch to fix the issue.
Comment #3
daffie CreditAttribution: daffie commented@Beakerboy: I think that the original code is right. The value of
:timestamp
get compared with the timestamp value in the database. When the value in the database is higher then use the value from the database and when that is not the case then use the value of:timestamp
. The value of:timestamp
should be the same, therfor the original is to me right. To your defence, in most queries the 2 placeholders should have a different name. Only this is one of those rare exceptions.Comment #4
Beakerboy@daffie, unless PDO is set to Emulate Prepares, this statement will cause PDO to throw an exception. This is why Drupal States that placeholder must be unique. SQL Server does not emulate prepares except in rare situations. The core drivers do.
Comment #5
alexpottComment #6
BeakerboyPutting back to needs review.
Comment #7
daffie CreditAttribution: daffie commented@beakerboy Can you add a comment to the patch with why this change is necessary. The stuff with when EMULATE_PREPARES is set to FALSE. Now we need a test that checks that the query uses the placeholders
:timestamp1
and:timestamp2
. We want to make sure that this change does not get reverted in the future.Comment #8
alexpott@daffie I'm not sure that testing this is correct. To test properly - i.e. that we don't do this again in the future is extremely expensive. I think in this instance it is okay to accept the fix and move on.
Comment #9
BeakerboyComment #10
daffie CreditAttribution: daffie commentedWith the post from @alexpott in comment #8, is this the patch for me RTBC.
Comment #11
alexpottThe one thing that might help to remember to not incorrectly "optimise" this in the future is a code comment. I didn't know the
rule so this would help future me remember that.
Comment #12
BeakerboySame code with the additional comment.
Comment #13
daffie CreditAttribution: daffie commentedComment add, back to RTBC.
Comment #14
xjmThis looks pretty good. I went back and forth about test coverage but can agree with no test. I also agree with the inline comment.
However, right now, the inline comment is making a claim that doesn't seem to be documented anywhere else. Can we link the reference in the comment? https://www.drupal.org/docs/8/api/database-api/static-queries
Thanks!
Comment #15
Beakerboy@xjm Added the url of the policy to the comment
Comment #16
BeakerboyComment #17
alexpottCommitted and pushed 07dd3e2ce7 to 9.1.x and 5d0d3ed093 to 9.0.x and 1b0cbeea4c to 8.9.x and 154038f140 to 8.8.x. Thanks!
Backported to 8.8.x as a very low risk bug fix that helps alternate db drivers.