Problem/Motivation
I have the following snippet in migration yml file:
foo:
plugin: migration_lookup
migration:
- migration_1
- migration_2
- migration_3
source: bar
source_ids:
migration_1:
- foo_bar
- bar_baz
My expectations are the following:
- For
migration_1
the source values should be:foo_bar
+bar_baz
- For other migrations (
migration_2
andmigration_3
) the source value should bebar
Unfortunately, it's not happening, because the original value is overwritten in the migrations loop and there is no way to go back.
Steps to reproduce
You can either try the snippet above or just take a look into plugin code: https://git.drupalcode.org/project/drupal/-/blob/9.2.x/core/modules/migr...
Proposed resolution
Simplify the yml file and specific source_ids only if it differs from the original source by refreshing the original source value before the processing another migration lookup.
Remaining tasks
Review, add tests and commit.
Comment | File | Size | Author |
---|
Issue fork drupal-3196583
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3196583-migration-lookup-source-values changes, plain diff MR !296
Comments
Comment #3
MatroskeenComment #4
MatroskeenComment #5
JoCowoodHey Matroskeen,
have you tried this solution?
Comment #6
MatroskeenYep, it works. According to this example, I can also move
migration_1
to the end of the migrations list and it'll work as well.However, I consider it as a workaround and I still think that this is not correct behavior.
If I specify:
I don't expect that it'll be applicable to every migration in the list after
migration_1
.Considering my particular case, I have many (more than 10) migrations to lookup. I would like to simplify the yml file and specific
source_ids
only if it differs from the original source.Comment #7
quietone CreditAttribution: quietone as a volunteer commentedAs a review swap Matroskeen asked me to, well, review this issue.
After reading the issue I understand the desire to make the yml simpler and I have added that bit to the proposed resolution. Because migration_lookup is ubiquitous we need to be very careful about changes and ultimately consult with mikelutz because he drove the work on converting it to a service.
I want to think through this slowly, If we have a process like this it will work well.
Then we add a lookup to another migration, it is reasonable that someone would do this and it would work.
But lets say the did this, have the members migration first. This would not work. The lookup would be done on 'members' first and the source values set to ['id']. If that fails a lookup on 'users' is done and the source values are not changes so ['id'] is used when it should be 'user'.
For this to work 'users' must be added to the source_ids, as is done in the example in MigrationLookup.
Is it a bug that this does not work? Possibly. At the very least it is a bug in the documentation that it is not explicit that when using multiple migrations with different source_ids they all must be listed. The suggested change in this patch will also require documentation changes so it seems fine to leave the status of this as a Bug.
I don't see any BC issues with this change, so that is good. I have not looked at the tests, but I do think a fail test is needed.
Changing to NW for tests and documentation.
Comment #8
MatroskeenAdded test and one more example to the documentation block.
Also fixed the indentation in another plugin example. Hopefully, it can be fixed within this issue.
Comment #10
Wim LeersThis could use some minor language tightening.
Nit:$this->migrateLookup
is not defined as a class property.I looked at the wrong file 🙈
Comment #13
catchRestoring status after HEAD was broken.
Comment #15
Wim LeersRe-testing — random fail in CKEditor tests.
Comment #16
MatroskeenBack to RTBC per #10.
Comment #17
larowlanSupernit🧐: I think this should read 'If the source identifier for a migration'
could this just be
$lookup_value = (array) $lookup_value
if we're touching these lines?Comment #18
MatroskeenYep, that works. Thanks for the review!
There is a mix of merge request and patches, so let's move back to merge request flow.
And moving back to RTBC after addressing #17.
Comment #19
larowlanComment #20
MatroskeenAhh, got it. Thanks!
Comment #21
quietone CreditAttribution: quietone as a volunteer commentedI applied the MR and read the patch and code. The improvements suggested in #10 and #17 have been done. The added documentation in MigrationLookup reads well and is easy to understand. The test is testing what it needs to.
Back to RTBC.
Comment #24
catchCommitted/pushed to 9.3.x and cherry-picked to 9.2.x, thanks!