Problem/Motivation

Discovered by PHPStan in #3178534: Start running PHPStan on Drupal core (level 0)

\Drupal\Core\Database\Driver\mysql\Connection::serialize() reads as follows:

  /**
   * {@inheritdoc}
   */
  public function serialize() {
    // Cleanup the connection, much like __destruct() does it as well.
    if ($this->needsCleanup) {
      $this->nextIdDelete();
    }
    $this->needsCleanup = FALSE;

    return parent::serialize();
  }

However the parent class has no serialize() method, and it does not implement the Serializable interface.

Steps to reproduce

Try to call serialize() directly:

>>> \Drupal::database()->serialize();
PHP Error:  Call to undefined method Drupal/Core/Database/Connection::serialize() in /var/www/html/drupal/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php on line 213

Proposed resolution

Remove this code.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#2 3210888.patch722 byteslongwave
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

longwave created an issue. See original summary.

longwave’s picture

Status: Active » Needs review
FileSize
722 bytes
longwave’s picture

This method was originally added in #1990544: Convert system_modules() to a Controller as a fix for when we serialized services. A followup was added to add a test for this in #2039731: Add test for cleaning up connection upon serialization but closed as not needed as we stopped serializing services, but this code was not removed from the driver.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

Thanks

  • larowlan committed 7d63c1f on 9.2.x
    Issue #3210888 by longwave: Undefined static method Drupal\Core\Database...
  • larowlan committed 3911088 on 9.3.x
    Issue #3210888 by longwave: Undefined static method Drupal\Core\Database...
larowlan’s picture

Title: Undefined static method Drupal\Core\Database\Connection::serialize() » [backport] Undefined static method Drupal\Core\Database\Connection::serialize()
Version: 9.3.x-dev » 9.1.x-dev

Committed 3911088 and pushed to 9.3.x. Thanks!

Backported to 9.2.x

Getting a second opinion on backporting to 9.1

larowlan’s picture

Title: [backport] Undefined static method Drupal\Core\Database\Connection::serialize() » Undefined static method Drupal\Core\Database\Connection::serialize()
Version: 9.1.x-dev » 9.2.x-dev
Status: Reviewed & tested by the community » Fixed

This is only a normal bug so after discussing with catch, decided to not backport as there's no pressing need for it

Status: Fixed » Closed (fixed)

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