#7 #1423460: [META] List of bugs and typos in Drupal core found by Spleshka

case PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE:
  $class_name = array_unshift($this->currentRow);

ref: http://www.php.net/manual/en/function.array-unshift.php

Comments

droplet’s picture

Status: Active » Needs review
StatusFileSize
new704 bytes

sorry, exclude other patch content

oriol_e9g’s picture

Status: Needs review » Reviewed & tested by the community

Good fix!

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Quick fix, -Novice +Needs tests

Hmm this looks like it could be tested, could we add some?

droplet’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

the feature only used in SQLite. do a research on Core, we don't test others databases. and no way to force testbot use SQLite ?

droplet’s picture

StatusFileSize
new3.4 KB

it uses first col as classname, @see http://php.net/manual/en/pdostatement.fetch.php

droplet’s picture

Issue tags: +Needs manual testing, +sqlite

"Needs manual testing":
official testbot do not support sqlite :(

Status: Needs review » Needs work

The last submitted patch, sqlite_fetch_fix.patch, failed testing.

droplet’s picture

Status: Needs work » Needs review
StatusFileSize
new4.73 KB

Add a new table so that won't affect other tests.

droplet’s picture

StatusFileSize
new4.62 KB

im not going to remove the comment. add it back :)

droplet’s picture

StatusFileSize
new4.62 KB
droplet’s picture

run an offline simpletest with sqlite DB and worked.

xjm’s picture

Issue tags: -Needs manual testing

Untagging per #11. Thanks @droplet!

droplet’s picture

10: sqlite_fetch_fix.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 10: sqlite_fetch_fix.patch, failed testing.

donquixote’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new4.47 KB

Coming from #2259947: Minor bug fixes in database system

New patch with changes to #10:

  • Rebased to current 8.x
  • Removed t() from assertion messages.
  • Replace PDO with \PDO (backslash prepended).
  • Flipped around some lines in testQueryFetchClassType():
    • Assertion on $record for "Classname field not found, as intended" moved into the loop, to avoid $record being undefined.
    • $records[] = $record moved to end of loop.
donquixote’s picture

StatusFileSize
new810 bytes
new4.47 KB

Style fixes.

The last submitted patch, 15: D8-1476782-15-StatementPrefetch-array_shift.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 16: D8-1476782-16-StatementPrefetch-array_shift.patch, failed testing.

donquixote’s picture

Status: Needs work » Needs review
StatusFileSize
new3.24 KB
new4.67 KB

The relevant fix was this:

      $this->installSchema('database_test', array(
       'test',
+      'test_classtype',
       'test_people',

The rest is just relocating stuff for aesthetic/conceptual reasons.

ekl1773’s picture

Rerolled the patch to match new test locations in head. Test files moved to /core/modules/system/src/Tests/Database

clemens.tolboom’s picture

+++ b/core/modules/system/src/Tests/Database/DatabaseTestBase.php
@@ -92,6 +93,15 @@ static function addSampleData() {
+      ¶

Whitespace problem

clemens.tolboom’s picture

Issue summary: View changes

(sorry for pasting into the summary)

I came here as we found another bug. Should that be in here as you are writing tests too or should I report a new issue?

      case \PDO::FETCH_COLUMN:
          if (isset($this->columnNames[$this->fetchOptions['column']])) {
            return $this->currentRow[$k][$this->columnNames[$this->fetchOptions['column']]];
          }
          else {
            return;
          }

$k is not defined there.

jhedstrom’s picture

Status: Needs review » Needs work

I marked #1555462: Syntactical errors found in StatementPrefetch as a duplicate. The patch in that issue addresses $k being undefined as mentioned in #22, and that bit should be added to this patch.

Katiemouse’s picture

Status: Needs work » Needs review
Issue tags: +CatalystAcademy
StatusFileSize
new5.05 KB
new1.19 KB

Hi, I am a high school student who is new to drupal. I have attempted to patch the two issues mentioned above :)

benjy’s picture

Thanks @Katiemouse, great work.

Could you please upload a version of the patch with only the test and not the fix. That way we can see that the test fails as expected.

Katiemouse’s picture

StatusFileSize
new3.96 KB

Hi this is the test only version :)

droplet’s picture

+++ b/core/lib/Drupal/Core/Database/StatementPrefetch.php
@@ -298,7 +298,7 @@ public function current() {
         case \PDO::FETCH_CLASS | \PDO::FETCH_CLASSTYPE:

@@ -322,7 +322,7 @@ public function current() {
         case \PDO::FETCH_COLUMN:

I think it should be a new issue and get it move forward faster. Although, it's almost on same class and place, it fixing different bugs.

#24 didn't add a new testcase yet.

Please file a new issue, Thanks. :)

jhedstrom’s picture

Status: Needs review » Needs work

Marked #2342191: Subtle bug in Drupal\Core\Database\StatementPrefetch::current() as a duplicate.

If #26 is the test only, it should fail without the fix...

catch’s picture

Priority: Normal » Major

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

daffie’s picture

StatusFileSize
new3.96 KB

Changed the test a bit. The problem is that the test passes for me on my local machine. The bug of this issue is really a bug. Lets see if it passes on the testbot.

daffie’s picture

Status: Needs work » Needs review

For the testbot

Status: Needs review » Needs work

The last submitted patch, 32: 1476782-32-test-only.patch, failed testing.

daffie’s picture

Status: Needs work » Needs review
StatusFileSize
new4.61 KB

The patch with the fix.

The last submitted patch, 32: 1476782-32-test-only.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 35: 1476782-35.patch, failed testing.

daffie’s picture

Status: Needs work » Needs review
StatusFileSize
new4.62 KB
new615 bytes

Minor change to see if it will fix the MySQL testbot problem.

Status: Needs review » Needs work

The last submitted patch, 38: 1476782-38.patch, failed testing.

daffie’s picture

Status: Needs work » Needs review
StatusFileSize
new3.97 KB
daffie’s picture

The patch with the fix and the test passes and the patch with only the test fails.

Ready for a good review.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

fabianx’s picture

Status: Needs review » Reviewed & tested by the community

RTBC - looks great to me

lendude’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

No longer applies, needs a reroll

lendude’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new4.69 KB

Rerolled

amateescu’s picture

Status: Needs review » Needs work
  1. +++ b/core/tests/Drupal/KernelTests/Core/Database/FetchTest.php
    @@ -80,6 +80,27 @@ public function testQueryFetchClass() {
    +        $this->assertIdentical($record->name, 'Kay', 'Kay is found.');
    +        $this->assertIdentical($record->job, 'Web Developer', 'A 26 year old Web Developer.');
    

    The expected value should be the first parameter passed to assertIdentical().

  2. +++ b/core/tests/Drupal/KernelTests/Core/Database/FetchTest.php
    @@ -80,6 +80,27 @@ public function testQueryFetchClass() {
    +    $this->assertIdentical(count($records), 1, 'There is only one record.');
    

    We should use assertCount() here.

    Also, I don't see why we need the extra $records variable. Can't we just assert the count for $result?

maximpodorov’s picture

This patch should be added to Drupal 8.7, or the statement of PHP 7.2 compatibility will be false (since passing just one argument to array_unshift is allowed in 7.3 only :) ).

lnunesbr’s picture

StatusFileSize
new3.91 KB

Based on #49, I have backported patch to D7.

Have ran tests locally, apparently looking ok.

---- DatabaseFetchTestCase ----


Status    Group      Filename          Line Function
--------------------------------------------------------------------------------
Pass      Other      database_test.tes   22 DatabaseTestCase->setUp()
    Enabled modules: database_test

[..snip..]

Pass      Other      database_test.tes   53 DatabaseTestCase->installTables()
    Table test_classtype created successfully.

[..snip..]

Pass      Other      database_test.tes  420 DatabaseFetchTestCase->testQueryFet
    Record is an object of class FakeRecord.
Pass      Other      database_test.tes  421 DatabaseFetchTestCase->testQueryFet
    Kay is found.
Pass      Other      database_test.tes  422 DatabaseFetchTestCase->testQueryFet
    A 26 year old Web Developer.

Further review and improvements would be much appreciated.

daffie’s picture

@lnunesbr: First the patch for Drupal 8 needs to be committed, before we start with backporting it to Drupal 7.

@maximpodorov: Yes, you are right about array_unshift. The use here of array_unshift is wrong. We are changing it to array_shift.

daffie’s picture

Version: 8.6.x-dev » 8.8.x-dev
Status: Needs work » Needs review
StatusFileSize
new4.68 KB
new1.51 KB

Fixed the remarks from @amateescu. With the exception of removing the $records variable. I have tried that and an assertCount() with the $results variable does not work.

init90’s picture

Looks good, only small nit: @see link should be \Drupal\Tests\system\Functional\Database\FakeRecord instead of \Drupal\system\Tests\Database\FakeRecord

daffie’s picture

StatusFileSize
new4.69 KB
new698 bytes

@init90: You are completely right. The class FakeRecord has been moved. Thank you for the good find!

init90’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! All main feedbacks were addressed, so set to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 6add1ca7a3 to 8.8.x and fb20927037 to 8.7.x. Thanks!

Backported to 8.7.x as this is a major bug and completely broken in HEAD. Nice to have test coverage at last.

diff --git a/core/tests/Drupal/KernelTests/Core/Database/FetchTest.php b/core/tests/Drupal/KernelTests/Core/Database/FetchTest.php
index 032339b5e0..a8b25c54bd 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/FetchTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/FetchTest.php
@@ -86,7 +86,7 @@ public function testQueryFetchClass() {
    *
    * @see \Drupal\Tests\system\Functional\Database\FakeRecord
    */
-  function testQueryFetchClasstype() {
+  public function testQueryFetchClasstype() {
     $records = [];
     $result = $this->connection->query('SELECT classname, name, job FROM {test_classtype} WHERE age = :age', [':age' => 26], ['fetch' => \PDO::FETCH_CLASS | \PDO::FETCH_CLASSTYPE]);
     foreach ($result as $record) {

Fixed

----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 89 | ERROR | [x] Visibility must be declared on method
    |       |     "testQueryFetchClasstype"
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

on commit.

  • alexpott committed 6add1ca on 8.8.x
    Issue #1476782 by daffie, droplet, donquixote, Katiemouse, Lendude,...

  • alexpott committed fb20927 on 8.7.x
    Issue #1476782 by daffie, droplet, donquixote, Katiemouse, Lendude,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.