Problem/Motivation

#2500513: Upgrade path for Shortcut 7.x was rolled back because we broke Postgres. It actually turns out that there was a serious bug that was only caught because of Postgres type system. Currently the Drupal\migrate\Plugin\migrate\id_map\Sql provides methods such as lookupDestinationId() and lookupSourceID that rely on the order of the values being passed in to be the same as the order they were defined in the source and therefore the order ensureTables() created the columns in the map table.

Proposed resolution

When we have multiple source ids, enforce the caller to pass through the values in a key => pair so we can correctly apply the filter conditions.

Remaining tasks

  1. Check through the idMap class and make sure we're no longer relying on the order of the fields but instead the keys.
  2. Refactor how we apply the conditions into a method because of how often it is done throughout the class
  3. Refactor the migration process plugin to accept the source id key in the yaml configuration.

User interface changes

n/a

API changes

Callers to methods on the idMap will now need to provide both key and value pairs rather than just an array of values. We can/will provide backwards compatibility when querying on only one value as there can be no confusion.

Data model changes

The schema for the migration process plugin will change although we don't currently have that schema in core. The structure for the migration process plugin may also change to support key => value rather than just values.

Comments

benjy created an issue. See original summary.

Status: Needs review » Needs work

The last submitted patch, 2500513-60.patch, failed testing.

benjy’s picture

Status: Needs work » Needs review
StatusFileSize
new12.47 KB

Re-rolled minus the shortcut migration stuff, will add some dedicated tests here although i think we're probably covered by the updated unit tests.

Status: Needs review » Needs work

The last submitted patch, 3: 2571499-3.patch, failed testing.

benjy’s picture

Version: 8.1.x-dev » 8.0.x-dev
Status: Needs work » Needs review

benjy queued 3: 2571499-3.patch for re-testing.

phenaproxima’s picture

Status: Needs review » Needs work

This is a great start, and a much more logical and developer-friendly way to look up IDs. I'm on the fence about whether we really need more test coverage (specifically, a fail patch for PostgreSQL).

  1. +++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
    @@ -428,8 +426,8 @@ protected function getFieldSchema(array $id_definition) {
    +      $query = $query->condition("map.$source_id", $source_id_values[$field_name], '=');
    

    Nit: No need for $query =. Or, for that matter, the = operator in condition().

  2. +++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
    @@ -467,11 +465,11 @@ public function getRowsNeedingUpdate($count) {
    +      $query = $query->condition("map.$destination_id", $destination_id_values[$field_name], '=');
    

    Ditto.

  3. +++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
    @@ -481,14 +479,20 @@ public function lookupSourceID(array $destination_id) {
    +    // The Migration process plugin doesn't currently have a way to provide the
    +    // source id keys so we have a compatibility layer for that. The order of
    +    // the source ids could be confused when using the Migration process plugin
    +    // and multiple source ids.
    

    I find this comment kind of confusing. Can it be reworded?

  4. +++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
    @@ -481,14 +479,20 @@ public function lookupSourceID(array $destination_id) {
    +      $query = $query->condition("map.$source_id", $have_keys ? $source_id_values[$field_name] : array_shift($source_id_values), '=');
    

    Ditto with $query = and the condition operator.

benjy’s picture

Status: Needs work » Needs review
StatusFileSize
new15.91 KB
new3.2 KB

Fixed the feedback. Also fixed getRowByDestination().

The last thing left todo here is check the interfaces and make sure all the docs are up-to-date.

Status: Needs review » Needs work

The last submitted patch, 8: 2571499-8.patch, failed testing.

The last submitted patch, 8: 2571499-8.patch, failed testing.

benjy’s picture

Status: Needs work » Needs review
StatusFileSize
new20.4 KB
new7.83 KB

Fixed up some docs and also fixed deleteBulk() and deleteDestination(). deleteBulk() has some bad naming because $source_id_values can actually be an array of $source_id_values. It's also not used in core so would be good if @mikeryan could test this?

Also a re-roll.

phenaproxima’s picture

It looks fine to me, but I'd like @mikeryan's input for RTBC.

mikeryan’s picture

+++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
@@ -428,8 +426,8 @@ protected function getFieldSchema(array $id_definition) {
+      $query->condition("map.$source_id", $source_id_values[$field_name], '=');

I agree with phenaproxima, let's take the opportunity to remove the needless ", '='" in all these query conditions.

As for deleteBulk() - in D7 that was used in association with bulk deletions on rollback, it has no known use case in D8, can we remove it here? Or, should I remove it in the rollback patch?

andypost’s picture

http://cgit.drupalcode.org/drupal/tree/core/modules/migrate/src/Plugin/m...

some this notaffected by patch? probably should return IDs with values

benjy’s picture

StatusFileSize
new2.39 KB
new20.38 KB
new21.22 KB
  1. Ah sorry, removed the $query = $query bit and missed the removal of '='
  2. deleteBulk() should probably be removed in a follow-up.

@andypost getSourceIdValues() already returns key/value pairs so that use case should be fine. If it didn't work we'd have had a few fails with undefined indexes i'd expect, patch attach shows that. However, it maybe is badly named/documented but that's an existing issue..

Status: Needs review » Needs work

The last submitted patch, 15: 2571499-15-FAIL.patch, failed testing.

phenaproxima’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 15: 2571499-15-FAIL.patch, failed testing.

phenaproxima’s picture

Status: Needs work » Needs review

ZOMG. It's a friggin' fail patch, testbot.

mikeryan’s picture

Status: Needs review » Reviewed & tested by the community

lgtm

benjy’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new20.38 KB

Re-uploading 15 because I didn't change anything in that patch from #11 that could have caused a fatal in that test. Unless something in head changed.

andypost’s picture

@benjy $id_map = $this->idMap->getRowBySource($this->currentSourceIds) as I pointed is not a getSourceIdValues() but protected variable that poorly documented

benjy’s picture

That protected variable is set from getSourceIdValues() just one line above with: $this->currentSourceIds = $row->getSourceIdValues(); We should update the docs, $source_id_values is used consistently used throughout the id map to reference the source ids structured as key/value pairs.

Seems the postgres issue was added to HEAD sometime between #11 and #15, will have to bisect to try and figure that out. If someone has Postgres and can help, that would be great.

benjy’s picture

StatusFileSize
new20.4 KB

Just going to try the patch that passed previously on Posgress before

benjy’s picture

The posgres fails seem to be almost random at this point, no idea what is going on, can someone reproduce locally?

phenaproxima’s picture

The posgres fails seem to be almost random at this point

I'm thinking the same thing, frankly. Take a look at this, which was just committed by @alexpott: #2572897: Promote and sticky options migrate to empty checkboxes. Given the patch in question, those test failures make absolutely no sense.

benjy’s picture

Posgres went green on it's own it seems, can I get a RTBC?

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Looks great! I love this change -- makes things MUCH easier to understand.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 24: 2571499-9.patch, failed testing.

The last submitted patch, 24: 2571499-9.patch, failed testing.

mikeryan’s picture

FYI, this is breaking on the rollback support committed yesterday, working on it...

mikeryan’s picture

Status: Needs work » Needs review
StatusFileSize
new25.09 KB
new8.25 KB

Well, that was harder than it looks... Ended up changing lookupSourceID() to return a keyed array to match how the source ID arrays are being used throughout, and currentDestination (added by rollback) to do the key thing like the rest of the patch. Also changed the executable rollback() to use deleteDestination() since that's what it's there for (although it actually never worked - fixed that) instead of the silly serialized source key. And, took the liberty of removing the unused bulkDelete()...

benjy’s picture

Changes look good to me. I think the SQLite failure was unrelated and we have a green one now anyway.

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

@Mixologic and @catch told me on IRC that we're OK RTBCing and committing based on DrupalCI results. If @benjy is OK with the latest patch, I am too.

mikeryan’s picture

Issue tags: +Needs change record
webchick’s picture

Status: Reviewed & tested by the community » Fixed

Fixed some Eg. -> e.g. usages and committed and pushed to 8.0.x. Thanks!

  • webchick committed 33cce8a on 8.0.x
    Issue #2571499 by benjy, mikeryan, phenaproxima: idMap source and...

Status: Fixed » Needs work

The last submitted patch, 32: idmap_source_and-2571499-32.patch, failed testing.

webchick’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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