Change record status: 
Project: 
Introduced in branch: 
11.2.x
Introduced in version: 
11.2.0
Description: 

The class Drupal\migrate\Plugin\migrate\source\SqlBase is updated. This is the base class for most SQL-based migration source plugins.

Previously, SqlBase::prepareQuery() was not invoked from doCount() nor __toString(). This leads to counts and string representation of the query that are not actually representative of the final query. This is because prepareQuery could be adjusted for query tag alters or any other more dynamic modifications. If you already adjust for this in a custom Sql-based plugin, that is no longer necessary.

Previously

  public function __toString() {
    return (string) $this->query();
  }

  protected function doCount() {
    return (int) $this->query()->countQuery()->execute()->fetchField();
  }

Prepare query allows folks to alter the query, which can adjust the count and string representation of the query.

Now

  public function __toString() {
    return (string) $this->prepareQuery();
  }

  protected function doCount() {
    return (int) $this->prepareQuery()->countQuery()->execute()->fetchField();
  }
Impacts: 
Module developers