Problem/Motivation
The documentation for this function is:
/**
* Executes a set of migrations in dependency order.
*
* @param string[] $ids
* Array of migration IDs, in any order.
*/however the function executes the migrations in the order they are passed, not in dependency order
Proposed resolution
Refactor the helper function to execute in dependency order. This shouldn't break existing usages, since executing migrations out of order would cause the tests to fail. This will allow future use of this method to work properly
Remaining tasks
Commit
User interface changes
none
API changes
none, as tests are not part of the API. This method is likely used in contrib though, and it would begin working as advertised.
Data model changes
none
| Comment | File | Size | Author |
|---|
Issue fork drupal-3015369
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:
- 3015369-migratetestbaseexecutemigrations-claims-to
changes, plain diff MR !5344
Comments
Comment #2
mikelutzComment #4
quietone commented@mikelutz, Nice find!
Comment #14
quietone commentedUpdate patch.
Comment #15
quietone commentedThat is good, no core tests are broken by this change.
So, I thought it would be good to confirm that re-arranging the order of the migrations in a Kernel test does work. I selected MigrateTaxonomyTermTranslationTest. I started by moving the last migration to the top and running the test. That work. I repeated that and eventually got a failure. You will see it in the patch and well as the absolutely useless serialization error message. #3197324: Exception trace cannot be serialized because of closure.
When you install the fix for that you get
I then debugged and found that
d7_language_content_vocabulary_settingsis last in the dependency list but it should be further up. I added a requirement ond7_taxonomy_vocabularyto it and re-ran the test. Andd7_language_content_vocabulary_settingswas still last! There is something more going on here and I am not seeing it.Comment #17
quietone commentedThe problem found above is addressed in #3371869: Fix dependencies of taxonomy term translation migrations
Thinking about how to test this I decided to make a fail patch by changing the order of migrations in an existing test. I chsse
d7/MigrateNodeTestand put the node translation migration before the node migration. That fails as expected withYou won't see that in the testbot results because of #3197324: Exception trace cannot be serialized because of closure.
Then I re-uploaded #14 which is the desired change so this doesn't get set back to NW.
Comment #19
smustgrave commentedFor this one going to rely on the test-only patch.
But can the full patch contain the tests to see if it fixed it?
Comment #20
quietone commentedFair enough. Here is a -fail and -test patch where the difference between them is the addition of the fix.
The patch intended for commit is the other one, which has just the fix. It does not have the change to the test that proved the fix works.
Comment #22
mikelutzJust reiterating here that we do not need to include the test with the committed patch here because this method is a test helper function, not core code. We don't need to test the tests. This should be good to go, but alas I wrote the original patch and can't rtbc.
Comment #23
smustgrave commentedIn that case think #20 should be good then. Thanks for uploading those @quietone!
Comment #25
smustgrave commentedRandom failure.
Comment #27
smustgrave commentedAnother random
Comment #28
quietone commentedReviewing the RTBC queue. The issue summary is update to date and complete. There are no unanswered questions in the issue summary. There are tests to prove the change works in #20 but note that those tests are not to be committed.
Comment #30
quietone commentedRandom fail, retesting.
Comment #31
quietone commentedBack to RTBC
Comment #32
xjmI think this looks pretty good -- the new implementation is much cleaner -- but what about the loss of the
assertNotEmpty()coverage?Comment #33
mikelutzI don't feel like it's necessary or useful. It was added here: https://www.drupal.org/project/drupal/issues/3021395#comment-12905204 in response to a bug in a test helper function for d6 node translations where an incorrect migration id was passed, resulting in no migrations being created. This again falls back into the category of 'testing the tests' to ensure we don't write a test calling for a plugin to be created that doesn't exist. Seems to me it would be more useful (in a follow-up) to add error checking and exceptions in MigrationPluginManager::expandPluginIds()
Which will silently allow you to request plugins that don't exist and return an empty array. MigrationPluginManager::createInstances() claims it
but in reality, ::expandPluginIds filters the requested plugin IDs against the discovered plugin IDs, so we are only ever calling $factory->createInstance() with a valid plugin id, and won't ever bubble up a PluginException from it.
Comment #34
mikelutzI opened #3390678: MigrationPluginManager::createInstances claims to throw a PluginException on invalid IDs, but does not. Just to see what breaks if we allow the plugin manager to throw exceptions on the invalid plugin ids.
Comment #35
mikelutzNow that I look at that expandPluginIds closely, it looks buggy... using the += on the derivatives is fine, preg grep will return the numeric keys from $all_ids which are unique, but then we throw $plugin_ids[] = $id in there, and if that gets assigned an index used by a derivitive in a later loop, that derivative won't get added... I think.
Comment #36
mikelutzYup, that's a nasty little bug.. Opened #3390693: MigrationPluginManager::ExpandPluginIds can lose derivative plugins under certain circumstances
Comment #37
mikelutz#3390678: MigrationPluginManager::createInstances claims to throw a PluginException on invalid IDs, but does not exposed even more issues... because expandPluginIds silently filters out non-existent migration ids, and we run the migration requirements through expandPluginIds before checking that the rows are processed, we actually aren't checking that required migrations exist when checking requirements. We only check that if they do exist that they have been fully processed...
Comment #38
mikelutzAll that to say, I think we can commit this without the assertNotEmpty check. The point of that was to make it harder to write tests with mistakes, but digging into it today, they fact that we can call createInstances() with invalid plugin ids and have it silently fail has caused mistakes in runtime code and migrations, so we need to fix those, and in doing so will make this check redundant anyway.
Comment #39
smustgrave commentedper @mikelutz in #38 sounds like this can move forward.
Comment #40
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue.
While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)
Comment #42
quietone commentedUpdate title, convert to MR, hiding all patches. The patch still applied so no changes needed to be made.
Comment #43
quietone commentedTests still passing, restoring RTBC.
Comment #44
xjmThe MR is currently kind of sort of turning off all tests but the one.
Comment #45
quietone commented@xjm, Sorry about that. All fixed now.
Comment #46
smustgrave commenteddrupalCi file changes removed.
Comment #47
xjmAmending attribution.
Comment #48
xjmThis is probably actually major as some nasty data integrity bugs could potentially result from them being out of order.
Comment #52
xjmCommitted to 11.x, 10.2.x, and 10.1.x as a data integrity bugfix. Thanks!
Comment #53
mikelutzThanks!
Comment #54
alexpott