While we're working on fixing up logging for process plugins, I'd like to see us improve upon the work from #2655154: Optionally log messages for skip_on_empty and skip_row_if_not_set.
That issue added the ability to put a log message into your migration yml when you invoke skip_on_empty or skip_if_not_set. However, the message must be entirely hard-coded directly in the migration configuration. Your message can't use any context from your migration row at all. It'd be a lot more valuable to be able to log messages that are specific.
For example, let's say your migration has some logic to drop various taxonomy terms that are considered invalid in the D8 version of your site. If you're in a d6_term_node migration, and you want to skip because the term is gone, instead of this:
field_department:
-
plugin: migration_lookup:
migration: d6_taxonomy_term
source: tid
-
plugin: skip_on_empty
method: row
message: 'Skipped missing department term'
It'd be nicer to be able do something like this:
field_department:
-
plugin: migration_lookup:
migration: d6_taxonomy_term
source: tid
-
plugin: skip_on_empty
method: row
message: 'Skipped missing department term ($tid)'
A) Yes, I know, technically this specific case could be sort of figured out since the message table has the incomprehensible source_ids_hash column, and if you manually JOIN against the map table, you can eventually figure out what tid you skipped. But that's a lot of hoop jumping. And I'm *sure* we can come up with other examples where the context you want to log doesn't happen to be one of the source IDs.
B) Yes, $tid is totally invalid above. That's meant to be shorthand for a better solution. ;) Things I tried initially with this migration before looking at the code and realizing the message had to be hard-coded directly in the configuration included:
skip_message:
plugin: concat
source:
- 'Skipped missing department term: '
- tid
field_department:
-
plugin: migration_lookup:
migration: d6_taxonomy_term
source: tid
-
plugin: skip_on_empty
method: row
message: '@skip_message'
Etc. ;)
Anyway, the specifics of exactly the best way to get this working are TBD. I'm just opening the issue for discussion on the basic concept before I get too lost in the details.
Regardless, this should probably be blocked on #2959125: Not able to add MigrateSkipProcessException message, so starting life here postponed.
Thoughts?
Thanks!
-Derek
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 2960204-18.patch | 3.65 KB | ravi.shankar |
| #13 | 2960204-13.patch | 3.65 KB | danflanagan8 |
Issue fork drupal-2960204
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:
Comments
Comment #4
quietone commentedThis was postponed on #2959125: Not able to add MigrateSkipProcessException message, which has been closed, so this in no longer postponed.
Comment #6
quietone commentedIn #2976098: MigrateExecutable should add details for the migration & destination property to exceptions that cause a row failure some context, the migration_id and the destination property, is being added to all MigrateSkipRowException and MigrateException. That will help.
However, that will not add the source value of the previous process on the pipeline as is suggested in the IS. Not sure how to get that value. Ideas anyone?
Comment #7
dwwThanks for the update! Yeah, I haven't had to do any migrations in a while, so I've stopped paying too close attention. ;) Still not sure how to actually do this properly.
Comment #8
josephdpurcell commentedI'm using the migrate_tools MigrateExecutable since it has batching and counts progress. I modified it to support capturing exceptions, see https://gitlab.com/drupalspoons/migrate_tools/-/issues/107.
I know this isn't directly related since this ticket is about capturing context, but the ticket on migrate_tools references a few various tickets that might be useful to anyone who wanders here.
Comment #12
longwaveThis would be super useful. I have a migration that uses
entity_lookupon an incoming field to look up a taxonomy term, and would like to know if the term doesn't exist (instead of creating it withentity_generate). I can useskip_on_emptyto detect this case but would love to include the field value in the message, the ID alone means a bunch of manual investigation to see what the missing field value is.Comment #13
danflanagan8This one caught my eye the other day and then I got an idea for a simple way to implement this. Obviously naming stuff is hard, but I added a new configuration option called
message_contextthat can accept one or more source/destination properties that are then used to fill placeholders in the message by leveraging sprintf.As an example of what this looks like, for this source data:
and this process pipeline:
the message is:
Baz was empty while foo was 123 and bar was abcHere's a patch with test coverage included.
Comment #15
shubham chandra commentedReroll the patch #13 with Drupal 10.0.x
Comment #16
anchal_gupta commentedI have fix cs error. Please review it
Comment #17
longwavePHPStan reports:
Comment #18
ravi.shankar commentedLooks like this
core/tests/Drupal/Tests/Core/Theme/ThemeHookTest.phpextra file got added in patch #16.So I've removed this file and created new patch.
Comment #19
danflanagan8Let's take a step back here. This never needed a reroll. The patch in #18 is identical to the patch in #13. No diff whatsoever. The patch in #13 applies and runs on 10.0.x.
Let's please not pollute the issue queues and waste testing resources with unnecessary rerolls.
I'm going to hide all the patches prior to #18, but for any reviewers out there, #13 is the most recent comment that is of any value.
Comment #20
danflanagan8As a little more context here, this issue predates a closely related issue: #2714529: Add source and destination IDs to the data returned by getMessageIterator()
These days (since July, 2019) the source ids and destination ids are all included in the migrate message tables. It's not simply the hash and there are no sql queries required to make sense of message anymore.
So I'm not sure that this feature would provide a ton of value. The implementation here doesn't add a ton of complexity and it's kind of neat. I could go either way.
Comment #21
mikelutzPer @danflanagan8 's request.
Comment #22
danflanagan8Ha, ha, thanks, @mikelutz
We discussed in the migrate meeting today (#3312722: [meeting] Migrate Meeting 2022-09-29 2100Z). The feeling was this would add complexity without adding much utility, especially given the details in #19. Less is more here.
I am going to steal this idea for the
skip_on_conditionprocess plugin in Migrate Conditions where the value will be considerably higher. I just made an issue: #3312746: Allow source/destination properties to appear in message for skip_on_conditionThanks!