Problem/Motivation
#2744639: Taxonomy term hierarchy migration incomplete corrected a bug where the taxonomy_term_hierarchy was not populated on migration for terms with no parent. The fix prevented the problem from occuring on future migrations, but did not fix the missing taxonomy_term_hierarchy data for previous migration runs.
Proposed resolution
Implement an update function to fix the taxonomy_term_hierarchy table.
Remaining tasks
Review. Questions:
- Should the update function go in taxonomy.install instead of migrate.install?
- Should this fix be postponed on #2543726: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration? Without that fix, it must do direct database access.
User interface changes
None.
API changes
None.
Data model changes
None.
Original report by @Benia
If I choose either "Selection box" or "Radio buttons" for taxonomy fields, I can't choose terms. The field will just show to output -None- and that's it. Autocomplete on the other hand, works just fine.
Further information
- It happens both on local (Ubuntu) && prod (CentOS).
- It happens when no contrib or custom modules are installed (core-only work).
- It happens for all content types, whether created before migration to D8 or after it.
- Each taxonomy field is already associated with a taxonomy vocabulary (autocomplete pulling works just fine and I can save the node with the terms pulled with autocomplete --- Without any problems or errors).
- No related errors in
drush ws-full. - Not a single problem appearing in status report.
- No special problems with the site whatsoever (surly not in all-core mode).
JS console check
These are the 3 JS errors appearing in console when I'm inside the back-end node-edit form:
> Use of getAttributeNode() is deprecated. Use getAttribute() instead. js__79M6UrZjAw3oNGnUjsWip12JsvnUZmJGA3h9LI0kuzE__LqE6uSZqCOZhJYW910TDw_HTQzBKUPTZxunfaWkalq8__lN6fPa32KCPrfa2DFR_PrioIXIdhNdWLxQDcTXnjQaA.js:55:488
> This site appears to use a scroll-linked positioning effect. This may not work well with asynchronous panning; see https://developer.mozilla.org/docs/Mozilla/Performance/ScrollLinkedEffects for further details and to join the discussion on related tools and features! drupal
> fbcdn-profile-a.akamaihd.net : server does not support RFC 5746, see CVE-2009-3555
How to reproduce:
I can't say exactly how to reproduce it as it happened since as I can remember after my migration.
If I remember correctly I first migrated from Drupal 7.44 to Drupal 8.1.3 (I now use 8.1.8). That's all there is to it, since then the problem started.
The migrate was basically core-based with this Metatag patch to include metatag data in the upgrade. Yet, as mentioned, even when the Metatag module is removed (even with flush all caches and after cron run), the problem persist.
In comment 17 I reported a milestone that might give you more data on what went wrong.
| Comment | File | Size | Author |
|---|---|---|---|
| #92 | interdiff-88-92.txt | 1.27 KB | jofitz |
| #92 | taxonomy_terms_not-2783423-92.patch | 4.29 KB | jofitz |
| #88 | interdiff_84-88.txt | 2.56 KB | jofitz |
| #88 | taxonomy_terms_not-2783423-88.patch | 4.08 KB | jofitz |
| #84 | interdiff-80-84.txt | 693 bytes | eli-t |
Comments
Comment #2
Benia commentedComment #3
Benia commentedComment #4
Benia commentedComment #5
Benia commentedComment #6
cilefen commentedComment #7
cilefen commented@Benia, please add the steps to reproduce this to the issue summary.
Comment #8
Benia commentedComment #9
Benia commentedComment #10
Benia commentedComment #11
Benia commentedComment #12
Benia commentedComment #13
swentel commentedIt sounds that this is rather a migrate problem than a fields problem no ?
Comment #14
Benia commentedMight be. Will you suggest changing component to Migration system?
Comment #15
Benia commentedComment #16
Benia commentedI've installed Devel and had an intro about it... I believe I could extract any data you might need. Please detail as much as you can so I will find it efficiently.
Comment #17
Benia commentedMilestone:
If I go to the taxonomy vocabulary page of every vocabulary whatsoever, and Just hit "Save" --- All of the terms in the vocabulary are deleted.
Conclusions:
This is not a problem in the backend form | This is not a problem in the JS | This is not a problem on the Drupal core.
The problem is migration related (as mentioned it exists since I migrated about 2 months ago).
If you need any data from any SQL table, please tell me and I will gladly try to extract it.
Comment #18
Benia commentedI mean to this page.
Comment #19
cilefen commented@Benia: Regarding this:
Is this yet another issue? This would be critical priority.
Comment #20
Benia commentedI would say it's not another issue as I'm sure from all my checks and tests it's related to the problem reported above if not the root cause of it.
Comment #21
cilefen commented@Benia: This issue needs a new title and a summary update, with a focus on the most serious aspect, because it will be difficult for people to understand. Have you seen the template and "How to create a good issue"? They help.
The component should be "taxonomy.module".
Comment #22
catch@Benia with an issue like this, it's most likely to be diagnosed if you're able to provide a copy of the Drupal 6 database and/or the migrated Drupal 8 database. Obviously would need to remove any sensitive information.
Moving to taxonomy module and tagging for migrate for now.
Comment #23
cilefen commentedComment #24
cilefen commentedComment #25
cilefen commentedComment #26
Benia commentedSadly I can't supply reproducing steps as this is a bug from migration...
What I would most need is instruction --- Where to go in the SQL and what to check there so to paste here.
If someone wants to help this way, I will most appreciate.
Comment #27
Benia commentedDear programmers, please make sure to read comment #17 where I reported a milestone.
Comment #28
Benia commentedComment #29
catch@benia see #22 - a copy of the pre- and/or post-migration databases would be most useful here. mysqldump would be best.
Comment #30
Benia commentedCan I share a partial mysqldump, if so, can you please tell me exact tables are needed from the post-migration site?
BTW, Is it possible its the PDO ?
Comment #31
Benia commentedComment #32
quietone commentedIt isn't clear to me if the D8 taxonomy tables have been checked to see if the data is there. Or, what is missing.
Comment #33
Benia commentedOf course, there is data in these tables but it is being saved in a "corrupted" way (corrupted? That's the right word in programming isn't it?).
Comment #34
quietone commentedThe issue summary says the data is deleted. I want to be sure I understand that point. So, to summarize, if you look in say, taxonomy_term_field_data you see the vocabulary and terms that no longer display since pressing save on a taxonomy vocabulary page. That it, the data is there but not displaying.
The MetaTag patch touches the taxonomy. Perhaps it incorrectly migrated something? Is it possible to rerun the migration with out the MetaTag patch? And then see if the problem persists? Just a thought.
Comment #35
Benia commentedMilestone:
I have now noticed that when I click "Save" for a single vocabluary, not only that all its terms seemingly deleted but actually all terms ---> In all other vocabularies, are also seemingly deleted.
I am not making this up. If I go to structure > Taxonomy, and there chose any given vocabualry and click "Save" it will suddenly appear as all other terms, of all vocabularies, have been deleted.
Table check:
I see all terms 30 terms/entries in that table (I have about three hundred and fifty nodes in the site and say 99% of these include at least one of these 30 terms). So, if they appear there, why Drupal no longer recognizes them after hitting save and present all term lists as empty ?
The problem here seems more and more about the SQL syntax in which they are stored after hitting"Save" ---> Drupal seem not to recognize it... Can you please give me an SQL query to try to run to "reset" the why in wihch these terms are saved there so Drupal might be able to recognize them?
About Metatag, its possible but I think I don't have any copy of the pre upgrade site and in any case I've already made many content changes inside nodes.
Comment #36
Benia commentedNext minor update should include reset to all related PDO syntax, I think.
Comment #37
heddnReviewed in weekly Migrate standup. See https://www.drupal.org/node/2735059 for a schedule of these meetings. Marking postponed for now.
Comment #38
catch@Benia, it's not possible to 'reset' the storage. Also we can't provide a fix for this without being able to see the data or having clear steps to reproduce the bug.
Can you provide a dump of your database? drush sql-dump --sanitize will remove e-mail addresses etc. Potentially just the term tables might be enough (but note the storage uses multiple tables, not just one).
Also could you check dblog and look for PHP errors on the site, that might also help.
Comment #39
Benia commentedCatch, will all 4 taxonomy tables be enough? If so, I will export them from PMA and put here.
If anything further is needed in the dump, please tell me...
Comment #40
steinmb commented@Benia If you only can share the term tables, make sure you include them all, but, yes.
Comment #41
Benia commentedHere are all four taxonomy tables.
Comment #42
Benia commentedComment #43
catch@Benia a configuration export from your site would probably help too.
Comment #44
Benia commentedAttached a taxonomy configuration export.
Comment #45
Benia commentedComment #46
Benia commentedComment #47
mikeryanRetitling - the terms are not actually deleted (they are present in the database), but they are not displayed in places where the hierarchy table is joined.
Your taxonomy_term_hierarchy table is empty - this strongly suggests this is an instance of #2744639: Taxonomy term hierarchy migration incomplete, which was fixed in 8.1.8. You say:
Just to be clear - you have not rerun your migration under 8.1.8, your migration was actually last run under 8.1.3? Then that's it, what you have is the remnants of a bug which has been fixed since your migration.
I believe you should be able to fix your database with the following query (be sure to backup your database before trying this!):
Edit: Actually, don't try this query, try the patch in the following comment.
insert into taxonomy_term_hierarchy (tid, parent)select tid, 0 from taxonomy_term_data
where tid not in (select tid from taxonomy_term_hierarchy)
Comment #48
mikeryanActually, forget about the manual query, please apply the attached patch and run db updates on your D8 site - see if that fixes it for you.
Patch reviewers - should the update go into the taxonomy module instead?
Comment #49
mikeryanLinking to the issue preventing a cleaner update function: #2599450: Drupal\Core\Entity\Query\QueryException: 'parent' not found in Drupal\Core\Entity\Query\Sql\Tables->ensureEntityTable
Comment #50
cosmicdreams commentedWhich appears to be the focus on this more current issue #2543726: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration. Looks like solve that issue may solve the one you've linked.
Comment #51
mikeryanBumping down to Major - migrate is experimental and not required to do database updates, and we do have the "Migrate critical" tag on this.
Updating the issue summary to reflect the details of what's going on here.
Comment #52
mikeryanComment #53
Benia commentedI tried to run the patch this way, and then flushed cache but don't see change.
If needed, I will rollback and try run it again differently.
Comment #54
mikeryanYou need to run database updates - what was added was an update function.
Comment #55
Benia commentedI tried to do "drush updb" but was told no database updates are available...
Could you please refer me to documentation about these db updates you mentioned? I am quite new to this...
Comment #56
mikeryanHaving trouble finding the D8 administrator docs, with the major doc re-org going on...
Can you verify that the patch actually took? Look at core/modules/migrate/migrate.install and make sure that "function migrate_update_8002()" is in there. If it is... I don't understand why it wouldn't be recognized.
Comment #57
Benia commentedIndeed, it is, last in the file:
Comment #58
mikeryanHmm, I don't understand why drush -y updatedb didn't pick it up - perhaps if you tried through the UI (http://example.com/update.php, where "example.com" is your web address)?
Comment #59
Benia commentedI tried it from Putty after navigating to my specific site's folder.
Comment #60
Benia commentedI would gladly upload any publicly-exposable data needed, in here.
Comment #61
Benia commentedAnd any data you need in private.
Comment #62
catch@Benia do you actually have migrate module installed on the site or did you uninstall after the migration?
Comment #63
mikeryan@catch: Good point - that's an excellent reason to put the update function into the taxonomy module...
Comment #64
Benia commentedI already uninstalled the module, as to keep minimal with enabled modules that aren't being used... Didn't imagine it's problematic in that case...
Comment #65
mikeryan@Benia: Please give this patch a try - it puts the update function in the taxonomy module. Be sure to run db updates (drush -y updatedb, or go to /update.php on your server).
Comment #66
mikeryanCleaner version of the patch, please skip the previous one.
Comment #67
heddnShall we move this over to taxonomy's queue then?
Also, this should really use the batch API. Entity save's are expensive and if there are a lot of terms to re-save, this is going to timeout.
Comment #69
mikeryanShamelessly stealing from system_update_8200()...
Comment #70
mikeryan*Sigh* - had temporarily set the limit to 10 because my test db had only 33 terms, restoring the 50...
@Benia - please use the last patch here. Don't forget to run the db updates after applying the patch.
Comment #71
Benia commentedIt seems there are still no dbupdates. I don't know what to say...
Comment #72
berdirpatch -p1 < filename
On a single line. That is the correct command. what you are doing doesn't actually do anything.
Comment #74
Benia commentedFor some reason I missed the dashboard notification regarding your comment Berdir. Today I got in saying to myself someone must have replied and I might have missed it.
I have good news, I ran the patch including the DB update (only 1 appeared for me to run) and now it's back to normal !
I tried to edit existing nodes, adding taxonomy data from both select-list && radio buttons, as well as creating new noes that way and it all went without a problem.
Thank you for creating that patch, dear Mike Ryan and for anyone else who helped !
Comment #75
mikeryanThanks for testing it Benia!
We leave this in "Needs review" now for technical review of the code, so we can get this patch into Drupal core and fix this situation for anyone else who runs into it...
Comment #76
mikeryanUpdated target version of the update function, obviously it's not going into 8.1.x.
@catch: Does this need a test? Note we'd have to munge the db (taxonomy_term_hierarchy table) to create the situation it's fixing.
Comment #77
matt bThanks @catch for pointing me here. I have previously run migrations prior to #2744639: Taxonomy term hierarchy migration incomplete being implemented so was missing taxonomy_term_hierarchy data and could still not see the terms in the ui. I have applied the patch from #76, run the DB update and confirm it worked successfully. I can now see all my imported terms in the ui under /admin/structure/taxonomy - thank you!
I now just need to figure out how to get the nodes to be associated with taxonomy terms as per the source site - however that is a separate issue.
Comment #78
matt b)-: I've just rolled back all the migrations and done a migrate-import --all and the taxonomy_term_hierarchy has reverted back. I no cannot see the taxonomy terms again.
Comment #79
phenaproxima$sandboxshould be type hinted.Should be
!isset() && is_array()<code>, because <code>array_key_exists()will return TRUE if the key exists and the value is NULL or some other invalid cruft.If any of the terms throw an exception or otherwise fail when
$term->save()is called,$sandbox['tids']might end up in an uncertain state. A while loop that continually pops term IDs out of the array would make me more comfortable.How is
$sandbox['#finished']used?Comment #80
eli-tShould address 1, 2, 3 in #79.
I'm sure the calculation of #finished can be clarified better though.
Comment #81
eli-tAdding interdiff
Comment #82
eli-tI've tested this with 1000 taxonomy terms nested three deep by
1) creating them in D7.44
2) running migrate_drupal through the ui to Drupal 8.1.3 and observing the initial problem where terms aren't displayed
3) updating to the code to 8.2.x HEAD plus the latest patch here and running update.php.
The terms are again visible and correctly nested.
Hence putting back to needs review.
Comment #83
phenaproximaThe array_shift() call should be the last thing in the loop, so that it will only be called if the term saves without blowing up.
Other than that, I'm OK with this.
Comment #84
eli-tNew patch reflecting comments made in #83 and interdiff.
Comment #85
eli-tComment #86
phenaproximaPreemptively RTBC assuming Drupal CI passes everything.
Comment #87
alexpottNice fix and sleuthing to find out the problem. Unfortunately this is exactly the type of upgrade path that needs testing. I think the best way will be to use the bare update and use database methods to insert terms without hierarchy and then run the updates.
Comment #88
jofitzAdd test for update hook.
Comment #90
phenaproximaSelf-assigning for re-review.
Comment #91
phenaproximaMissing @inheritdoc comment.
I'd like to see a few comments explaining what is being set up here.
Nit: The fetchCol() calls should be on their own line.
Use assertSame(), not assertIdentical().
Comment #92
jofitzComment #93
phenaproximaGood catch. My bad.
Otherwise, I think this looks fine and dandy. Let us proceed with it. Thanks, @Jo Fitzgerald!
Comment #94
alexpottThis at best will make it into 8.3.x
This should point to https://www.drupal.org/node/2543726
It's a shame we have to use a database query and not an entity query.
Also should we be concerned about the number of tids here potentially? I guess it could be very very long. Maybe we should get a new 50 every time until there is none?
We're debating adding a setting for 50 in ...[issue]
Comment #95
mikeryanComment #96
mikeryanDoesn't really seem critical at this point - it's been a long time since the bug causing the situation was fixed.
Comment #101
docans commentedlooks like i am having the same issue
Greetings
I am migrating taxonomy from a tab file, The script and everything runs well and all the 279 taxonomies show in the migration status as beeing completed.
But when i go to view my taxonomies in drupal, only 180 of the taxonomies show up in the taxonomy vocabulary. I even tried creating a view to see all the taxonomies but it only shows 180 and i cant find the rest.
Here is a my migration script
Comment #102
digitalfrontiersmediaI know this is a really old thread, but came across it while looking at some old patches during an update. And it reminded me of another issue that sounds related that I documented here: #2985762: Terms created when override_selector = TRUE don't appear on Terms List/Overview page
People experiencing missing terms after a migration may want to check that out. It has some thoughts on a workaround and a patch, although it's pretty old and not sure if it still applies.
Comment #104
quietone commentedThe bug causing this was fixed in July 2016 but this update function was never committed and it would fix long standing migrations.
Moving to migration system since this fix is a fix for a problem caused by migration and the migrate maintainers will see it.
Comment #105
quietone commentedThis issue was discussed as a migrate maintainer meeting, #3199420: [meeting] Migrate Meeting 2021-02-25 Item #10. The conclusion was that this can be closed as outdated. Read the minutes for the full discussion.