Problem/Motivation

SourcePluginBase has this line in its next() method:

$row = new Row($row_data, $this->migration->getSourcePlugin()->getIds(), $this->migration->getDestinationIds());

However, Row's constructor looks like this:

public function __construct(array $values = [], array $source_ids = [], $is_stub = FALSE)

$is_stub is supposed to be a boolean. SourcePluginBase is giving it an array.

The only reason this has ever worked is because Migration::getDestinationIds() returns the migration's $destinationIds property, which is an empty array -- that its default value, and nothing ever sets it differently; it's a vestigial property that should be removed from the Migration class. And the empty array evaluates to false (even PHPUnit's assertFalse() will not catch this).

So, entirely by accident, Row::isStub() does what it's supposed to do. If anything in Migrate did $row->isStub() === false, it would break.

Additionally, the call uses a roundabout $this->migration->getSourcePlugin()->getIds() call instead of simply calling $this->getIds()

Proposed resolution

SourcePluginBase::next() should neither call another copy of itself, nor pass a third argument when creating the row. It defaults to FALSE anyway.

Remaining tasks

Write a fail patch, write a passing patch, RTBC, and swiftly commit.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

Fixed a bug where \Drupal\migrate\Row::isStub() could return an incorrect value, depending on how the object was instantiated.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

phenaproxima created an issue. See original summary.

phenaproxima’s picture

phenaproxima’s picture

Status: Active » Needs review

Forgot to change status.

phenaproxima’s picture

Issue summary: View changes
mikelutz’s picture

Title: SourcePluginBase::current() has no idea what it's doing » SourcePluginBase::next() calls Row constructor incorrectly
Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Discussed in slack with PhenaProxima. This is a clean, easy to understand, and obvious fix. I tweaked the issue title and summary a bit for accuracy. RTBC on appropriate red and green tests.

The last submitted patch, 2: 3017119-2-FAIL.patch, failed testing. View results

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Bring on strict types.

Committed and pushed 30cfcd03d0 to 8.7.x and 698f4703ff to 8.6.x. Thanks!

  • alexpott committed 30cfcd0 on 8.7.x
    Issue #3017119 by phenaproxima: SourcePluginBase::next() calls Row...

  • alexpott committed 698f470 on 8.6.x
    Issue #3017119 by phenaproxima: SourcePluginBase::next() calls Row...

Status: Fixed » Closed (fixed)

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