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
The Simpletest-specific table prefix handling code in _drupal_bootstrap_database()
includes the following test:
elseif (is_array($value['prefix'])) {
$current_prefix = $value['prefix']['default'];
}
Obviously, there's an invalid assumption there--that just because $value
is an array it therefore has a value at index "default". If it's wrong, it causes test exceptions.
Note: The problem no longer exists in Drupal 8.
Proposed resolution
Make the logic smarter.
Remaining tasks
Review.
User interface changes
n/a
API changes
n/a
Comment | File | Size | Author |
---|---|---|---|
#8 | drupal.simpletest-table-prefixing-fix.2205817-8.patch | 840 bytes | TravisCarden |
Comments
Comment #1
TravisCarden CreditAttribution: TravisCarden commentedComment #2
Steven Jones CreditAttribution: Steven Jones commentedYup, the DB layer seems to have the following code:
Which means that a non-set 'default' key in the array will just be silently ignored, apart from in
_drupal_bootstrap_database()
as you mention.I'm not sure if Simpletest is capable of testing that this issue is there/has been fixed etc. I guess if we test DB prefixing somewhere, then we should be able to test this too.
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedI added condition to check the existence of 'default' key in $value['prefix'] array. If it does not exists fall back to Empty String
Comment #4
JayeshSolanki CreditAttribution: JayeshSolanki commentedComment #5
JayeshSolanki CreditAttribution: JayeshSolanki commentedLooks good to me.
Comment #6
TravisCarden CreditAttribution: TravisCarden commentedThat probably works, but I think it compensates for a defect in the code rather than fixing it. Attached is a solution that I think fixes the root problem and results in simpler, more readable code.
Comment #8
TravisCarden CreditAttribution: TravisCarden commentedOops; backwards patch. Take two.
Comment #9
davic CreditAttribution: davic at CI&T commented#8 Tested and is working fine, and does it smoothly. Seems to be a good approach.
Comment #10
stefan.r CreditAttribution: stefan.r commentedDo we have an example where this snippet should apply, or even better, a test?
Comment #11
stefan.r CreditAttribution: stefan.r commented