Closed (fixed)
Project:
Drupal core
Version:
8.6.x-dev
Component:
taxonomy.module
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
6 Sep 2018 at 20:47 UTC
Updated:
28 May 2019 at 06:49 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
logickal commentedCan confirm, we are seeing a similar issue in our testing of 8.6.0. Our taxonomy_term__parent table has 105 rows while taxonomy_term_hierarchy in the 8.5.6 schema had 19,624.
Comment #3
longwaveThis is critical if it is causing data loss on upgrade.
Comment #4
cilefen commentedComment #5
franco cazzaro commentedHi,
in my tests the limiting line "range" is useless and probably inserted only for the tests under development.
The logic, however, present later ( if ($ sandbox ['# finished']> = 1) { at line 75 ) require further investigation.
This patch MUST be applied after update core but BEFORE launching DB update.
Ciao
Franco
Comment #6
longwaveComment #8
plachThe ranged query is needed to avoid updating all terms in a single batch, so simply removing it is not the solution. However it may indicate we are not tracking the
$sandbox['current']id correctly.Comment #9
plachWhat about this?
Comment #10
catchWe could use test coverage with > 100 terms for this.
Also there's a setting for entity update batch size, i.e.
Settings::get('entity_update_batch_size', 50);(this would allow the test database to contain a smaller number of rows and also gives sites more flexibility.Instead of $sandbox['current']++ in the loop we could maybe do $sandbox['current'] += count($hierarchy) but they should be the same in the end.
The patch looks OK - the second argument should be the number of rows (the limit), however the current code should just be making that number bigger, so I can't really see why it's causing the issue here.
Comment #11
franco cazzaro commentedHi,
rigth is not a good idea updating all terms in one time, but, the block of code limited at 100 items is callede only once time, so, after the update the new table taxonomy_term__parent count exactely 100 items in opposite of old taxonomy_term_hierarchy with more tan 1000 items.
Ciao
Franco
Comment #12
longwaveThere is no sort on the query; is LIMIT without ORDER BY guaranteed to be deterministic in MySQL (and other databases)?
Comment #13
catchNo there's no guarantee on order and that's definitely a bug. Updated patch to include that.
@franco cazzaro Drupal updates are batched - i.e. the update function is supposed to run multiple times, so the bug is in that not happening properly (either query ordering or $sandbox not being updated correctly.
Comment #14
longwaveI spotted another bug that I mentioned in #2997982: Orphan term hierarchy records can cause taxonomy_update_8502 to enter an infinite loop - if the same tid arrives in two separate batches we will attempt to reuse delta 0 for the second batch. I think $tid should be stored in the sandbox so we remember it across batches. Is it worth fixing this here as well, or in the other issue?
Comment #16
plachI'm wondering whether it would be easier/possible to just perform an insert from select and skip the batch altogether.
Comment #17
longwaveNot sure how we would generate the deltas in pure SQL with an INSERT INTO ... SELECT statement. It is perhaps technically possible, but probably not portable across database engines.
Comment #18
catch@longwave I think it's worth doing that here to avoid two competing patches or dependencies between them, we should mark the other issues as duplicate of this.
Comment #19
plach@catch:
I agree to bring that patch over, however the two issues seem to reports slightly different problems: the one here is caused by performing the update in multiple batches, while #2997982: Orphan term hierarchy records can cause taxonomy_update_8502 to enter an infinite loop seems to have troubles with just a single batch.
Comment #20
catch@plach yes this seems like a different bug just not sure how to manage fixing both bugs in independent issues.
Comment #21
plach@longwave, #17:
This seems to be portable but it involves temporary + filesort usage, so it might time out on large datasets:
@catch, #20:
Do you mean we'd want to make sure both are fixed before committing anything?
Comment #22
catchMySQL queries don't count towards max_execution_time so it shouldn't time out in PHP. The only risk is if apache or varnish has a short timeout when running via the browser.
@plach actually I don't think it matters, this is much more critical than the multiple hierarchy one, so we might want to proceed with different issues after all if it means we can hotfix this one quickly.
Comment #23
plachYep, I was referring to browsers updates.
Comment #24
longwave@plach Oh, that self join is clever, nice work - but I also worry about how long it might take on sites with extremely large numbers of terms, which is the reason we batch in the first place I guess?
Comment #25
longwaveBack to NR because #13 failed on some spurious curl error.
Comment #26
franco cazzaro commentedHi,
@catch, thanks for clarification, really I'm not so skilled in core and I can only thank you for your suggestions.
If can be useful for somebody this (rude) way works:
in file taxonomy.install rename taxonomy_update_8601 in taxonomy_update_8500
remming out all other hook_update and run drupal updb
re-enabiling taxonomy_update_8501 ~ 8504 and re-run drupal updb
All my taxonomies are imported.
Ciao
Franco
Comment #27
logickal commentedNot going to mark this reviewed, but want to follow up from my "me-too" to share some insights from our testing for others that hit this issue.
We tested this with a build-in-progress with multiple migrations and ~20k taxonomy terms running PostgreSQL. We found that nearly all of our taxonomy terms had "disappeared", but the term data was still in the database. We were able to repair in place by re-running our migrations, but that obviously isn't going to be an option for most.
Testing patches this morning and I can confirm that the patch in #13 does fix the issue on database updates, when run with Drush's
command. Interestingly, the corresponding Drupal Console command still fails with the patch, only performing 100 rows (one batch cycle) through the process. I haven't dug into the differences between the two enough to give more detail, but that's another potential wrinkle that folks might want to be aware of. We have NOT tested with update.php yet, as our docker containers are built to refuse connection to those files (because you have Drush and Console, rite?) :D
Locally, the Drush command executes relatively quickly in our cli containers - on the order of a couple of seconds. I'm not sure that 20k terms is the largest dataset, but I didn't experience anything that makes me concerned for query performance off the bat.
Comment #28
cilefen commented#2998221: Primary language taxonomy terms unpublished during 8.6.0 upgrade
Comment #29
plachI just performed some testing of the query proposed in #21. In my local env (MacBook Pro, 2,6 GHz Intel Core i7, 16 GB 1600 MHz DDR3, OS X 10.10.5 :D, MySql 5.5.38) I get the following numbers for the following query:
The latter seems definitely at risk of timing out when running
update.phpvia browser. It's fairly likely that sites with such numbers would update via drush but we cannot rely on that, so I guess this rules out the "insert from select" approach.Comment #30
plach@franco cazzaro:
Would you be able to test patch #13 on a DB backup and check whether it fixes the issue you reported?
Comment #31
franco cazzaro commentedHi,
first sorry for my elementary english
@plach I've tried the #13 but not, no luck.
I run drupal console (drupal updb) to stay outside browser, nginx, php7.1-fpm possible timeouts.
But, I'd like to try (from my poor knowledge of this level of software) put Your eyes in a different direction.
First, performance: sure is not, if I change the range (100) in SQL on a value superior than my Terms update works well.
So, as wroted in changelog https://www.drupal.org/project/drupal/releases/8.6.0 Taxonomy is converted in a more standarized format, at DB level the table taxonomy_ter_hierarchy goes to taxonomy_term__parent with a new format.
What actually happens during the batch cycle that produces a new partial tree is that something later in updates that interrupts the cycle.
The proof is that at the end of the update the taxonomy_term__parent table contains exactly 100 elements, and, the instructions of 8502 which remove the taxonomy_ter_hierarchy table at $sandbox['#finished'] time are NOT executed and the table remains in place.
So is sure that update batch cycle runs only one time.
If You simply remove the taxonomy_update_8503 and taxonomy_update_8601 the new table taxonomy_term__parent is totally populated and taxonomy_ter_hierarchy correctly dropped
This is the update output:
Executing required previous updates
Executing update function "8501" of module "taxonomy"
Executing update function "8502" of module "taxonomy"
Executing update function "8503" of module "taxonomy"
Executing update function "8600" of module "block_content"
Executing update function "8600" of module "comment"
Executing update function "8600" of module "dblog"
Executing update function "8600" of module "media"
Executing update function "8601" of module "menu_link_content"
Executing update function "8601" of module "taxonomy"
Executing update function "add_views_reusable_filter" of module "block_content"
Executing update function "views_string_plugin_id" of module "datetime_range"
Executing update function "scale_and_crop_effect_add_anchor" of module "image"
Executing update function "storage_handler" of module "media"
Executing update function "change_delete_action_plugins" of module "system"
Executing update function "extra_fields" of module "system"
Executing update function "language_item_callback" of module "system"
Executing update function "clear_entity_bundle_field_definitions_cache" of module "taxonomy"
Executing update function "clear_views_data_cache" of module "taxonomy"
Executing update function "handle_publishing_status_addition_in_views" of module "taxonomy"
Operating in maintenance mode off
// update:entities
Operating in maintenance mode on
Starting the entity updates
Finished the entity updates
Operating in maintenance mode off
// cache:rebuild
Hoping this can be useful
Ciao
Franco
Comment #32
longwaveThank you for trying the patch and reporting back.
This points to a bug in Drupal Console not performing batch updates correctly. @logickal also said
However the patch in #13 is still valid as this solves a different issue regarding consistency between batches.
Comment #33
franco cazzaro commentedHi,
@longwave Yes, I can confirm, most probably the problem is relative to drupal console.
Since after composer update core pointing browser result in error I've tried only drupal console as usually.
Doing now directly with browser at /update.php works fine.
Sorry for my not a so good issue.
Ciao
Franco
Comment #34
benjifisherThis is the patch from #13:
The first change looks right: the API docs for Select::range() include
Adding the two
orderBy()calls in that order looks odd to me. That means sort bytid, and if there are multiple rows with the same value oftid, then sort byparent.I guess the point is that Drupal supports taxonomy terms with multiple parents, although I have never seen it. Even though it looks odd, it is the right thing to do.
I have reviewed, and it looks good to me, but I have not tested, so I will leave this issue as "Needs Review". I am not sure whether the core maintainers will require test coverage for this change.
I am also adding the "Needs issue summary update" tag.
From Comments #27 and #31-33, it seems that the initial report comes from a bug in Drupal Console. Has anyone created a bug report for that project? It would be nice to have a link in the comments here.
The issue summary should describe the problem(s) that the patch actually solves. I guess there are two problems:
taxonomy_term_hierarchy, is very large, then the original code will try to process about sqrt(N) of them at once, which may use up PHP's memory.ORDER BYclause, SQL does not guarantee a consistent order, so this would not be a bug in the database.)Both of these problems are hard to test, so I hope that the core maintainers will not insist on test coverage.
Comment #35
joonapenttila commentedHi,
I got issue with taxonomies. I will see all of terms when I am logged in to site. When i log out, I see only few terms. Rollback to 8.5.7 and everything works fine.
Comment #36
joonapenttila commentedMy issue is solved. Need to go term settings and click 'This translation is published'.
Comment #37
cilefen commentedComment #38
plachThis merges #13 with #2997982-7: Orphan term hierarchy records can cause taxonomy_update_8502 to enter an infinite loop and allows to fix three different issues with
taxonomy_update_8502:It seems we clarified that parts of the problems reported here were caused by Drupal Console and should be fixed there. By just inspecting the code I cannot identify any other obvious problem with the update logic, so I'm +1 to RTBC/commit this as soon as we have a final confirmation this is good by the people that were affected by this and showed up in #2997982: Orphan term hierarchy records can cause taxonomy_update_8502 to enter an infinite loop. I asked them to move here.
I will retitle/update the issue summary shortly.
Comment #39
plachUpdated IS
Comment #40
plachCredited @longwave for his work in #2997982: Orphan term hierarchy records can cause taxonomy_update_8502 to enter an infinite loop.
Comment #41
plachMinor IS update
Comment #43
plachExpected failure for the test-only patch.
Comment #44
plachMentioned the Drupal Console issue in the IS.
Comment #45
plachComment #46
larowlanCode looks good to me, we just need to some people to manually test and report back
Comment #47
bzrudi71 commentedLooks good. I just migrated 40.000+ terms on PostgreSQL with 512MB PHP-Memory limit using drush and patch from #38. I tested on two boxes and run every update twice. Nice work, thanks!
Comment #48
larowlanBased on #47
Comment #49
longwaveIt appears Drupal Console doesn't make any attempt to deal with batched updates:
https://github.com/hechoendrupal/drupal-console/blob/master/src/Command/... implies that the update function is only ever run once and the $context parameter is not inspected.
https://github.com/hechoendrupal/drupal-console/issues/3574 and https://github.com/hechoendrupal/drupal-console/issues/3787 are related questions about batch jobs but have no response.
edit: raised https://github.com/hechoendrupal/drupal-console/issues/3929
Comment #50
plachThanks @longwave, we'll mention your findings in the 8.6.0 release notes.
Comment #51
espurnes#38 works.
Previously I thought it was not working because I was getting [error] SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-0-0-es' when I was updating with drush updb.
The problem was on my side. I was using
drush sql:cli < db-backup.sqlover my local db, that I tried to update previously without the patch.
the drush sql:cli was overriding the old tables, but not removing the tables creaded by previous drush updb like (taxonomy_term__parent). So when I tried to update the db with the patch applied the following error appeared:
Solution
I removed all the database tables and ran
drush sql:cli < db-backup.sqlagain.
This time the update worked with no errors.
I hope it helps.
Comment #52
catchCommitted/pushed to 8.7.x and cherry-picked to 8.6.x. Thanks!
Comment #53
plach@joonapenttila:
That issue seems related to #2998221: Primary language taxonomy terms unpublished during 8.6.0 upgrade.
@espurnes:
Thanks for the feedback, that sounds exactly what happened in #2997982: Orphan term hierarchy records can cause taxonomy_update_8502 to enter an infinite loop.
Comment #54
kim.pepperI'm not seeing the commit in 8.6.x or 8.7.x
Comment #55
plachIt seems they were not actually pushed.
Comment #57
catchNow pushed, sorry folks.
Comment #59
sam152 commentedIt would be great to solve the logic for this problem space once, adding a related issue: #2977990: Add a helper class to make updating content entities easy.
Comment #60
wim leersApparently nobody ran this update path since this got committed to Drupal 8.6 in January of this year. 😲 😞
@fgm reported a problem similar to this in #2543726-362: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration, but then discovered that this was a bug in some Drush 9 plugin/some new behavior in Drush 9.
Comment #61
zenimagine commentedI have not seen any error when I update the Drupal 8.6 release
I have about 80 taxonomy terms.
How do I know if I need to restore the site ?
Thank you
Comment #62
longwaveThe various errors mentioned in this issue only apply for sites with more than 100 terms. Sites with 100 terms or less would have them all processed in a single batch (whether you use update.php, Drush or even Drupal Console), which bypasses the mentioned bugs.
Comment #63
zenimagine commentedI was wrong. I have 219 terms in all. Distributed in 19 vocabularies.
When Drupal 8.6 was released on September 6th, I updated it with drush updatedb
How can I check that the update has gone smoothly?
Comment #64
benjifisher@zenimagine: I assume you backed up the database before the update!
You can compare the actual database tables:
taxonomy_term_hierarchybefore the update andtaxonomy_term__parentafter the update.You could also install your database backup on a test server. Check each vocabulary and compare to what you have on the live site.
Note that this problem only potentially affects the parent/child relations in vocabularies. If most of your vocabularies are flat (no parents) then you might have had fewer than 100 terms in the
taxonomy_term_hierarchytable, in which case you are safe.Comment #65
anthonyjs commentedI'm confused. I don't use taxonomy on my site as far as I'm aware. Should I update to 8.6.1 from 8.6.0, or ignore the update, or what?
Comment #66
philosurfer commented@anthonyjs if you are not using more than 100 Taxonomy terms, and it sounds like you are not using any, then this issue does not apply.
And yes, you should update to 8.6.1 when you get a chance. :)
@everyone_else.. thanks for the hard work here!
Comment #67
zenimagine commentedI do not have much database management. I added 2 screenshot before and after the update.
After the update I created 3 new taxonomy terms.
Is this correct ? Is there anything else to check?
Is the update ok?
Thank you
Comment #68
benjifisher@zenimagine: Your screenshots only show the summary of the queries. You would have to compare the full results.
I think the two tables (
taxonomy_term_hierarchybefore the update andtaxonomy_term__parentafter the update) should have the same data. The column names will be different.Comment #69
zenimagine commented@benjifisher
How do I do with phpmyadmin to see the complete result ?
Comment #70
zenimagine commentedIn my table there is a column TID and a column PARENT.
In the PARRENT column everything is at 0 before and after the update.
What do you mean by
?
Comment #71
minnoce commentedI tried to update my Drupal 8.5.7 to 8.6.1 (from tar.gz package and via update.php admin interface), with 3 simple flat taxonomies (all with less than 10 terms) and I found the following error:
Comment #72
plachThis seems related to #2997982: Orphan term hierarchy records can cause taxonomy_update_8502 to enter an infinite loop.
Comment #73
minnoce commented@plach: Yes, it's possible. I posted my comments also on #2997982. Thanks!
Comment #74
trevorbradley commentedReporting in from #2998221: Primary language taxonomy terms unpublished during 8.6.0 upgrade.
My site had multilingual taxonomy terms that happened to have "This Translation is published" unchecked. (The content_translation_status of the taxonomy_field_term_data table was 0).
When I upgraded to 8.6.0, a view that referenced these taxonomies had a new filter added: "Taxonomy Term Published = True". I've checked against my 8.5.6 install and the filter was definately added to the view.
This caused a number of rows tagged with these terms to simply vanish, and my site to "break" (though an argument could be made that it was already broken before).
I simply checked the "This translation is published" where it was missing on my sites, and the error resolved itself. I left the filter in place on the views.
Comment #76
effulgentsia commentedAdding issue credit to @samuhe for reporting #2997982: Orphan term hierarchy records can cause taxonomy_update_8502 to enter an infinite loop, which started as a duplicate of this before it veered off into solving a different bug.
Comment #77
zenimagine commentedCan someone confirm that it's good for #70 ? Thank you
Comment #78
Mitch5713 commentedIs this related to the above:
Database updates
Out of date
Some modules have database schema updates to install. You should run the database update script immediately.
Entity/field definitions
Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.
Taxonomy term
The Publishing status field needs to be uninstalled.
The Term Parents field needs to be updated.
Comment #79
tipit commentedThis is marked as fixed but at least it does not work in my projects. Am I the only one?
Comment #80
longwave@TipiT This was fixed in the 8.6.1 release, what version are you using? What errors are you getting or symptoms are you seeing? There have been similar issues reported such as #2998221: Primary language taxonomy terms unpublished during 8.6.0 upgrade which are still under investigation.
Comment #81
tipit commentedI try to upgrade 8.53 -> 8.61.
Result:
Cache rebuild complete. [ok]
Finished performing updates.
So the behavior is like described in 2997982 but the patch did not solve the problem.
Comment #82
longwaveIf you are restoring from a backup, you need to ensure you delete the taxonomy_term__parent table before rerunning the updates. The taxonomy_term__parent is created by the update but does not exist in the backup, so it will not be automatically wiped if you just restore the old database over the top of a broken one.
@plach Do you think we should reconsider adding a truncate here? I don't see how it can harm, it can only help in these cases, as far as I can tell?
Comment #83
sealionking commentednot only the taxonomy hierarchy,but also the menu hierarchy.
Comment #84
effulgentsia commented@sealionking: Menu hierarchy issues are likely unrelated to this issue. Can you open a new issue with details on what you're seeing, such as what version you're updating from, what version you're updating to, and what messages, if any, were output during the update process?
Comment #85
plachI'm not sure to be honest: on one hand I agree that it would make the upgrade UX better, but if people need to run the update twice, it means something went wrong previously and it would be good to find out what it is.
Comment #86
plachDiscussed #85 with @catch: neither of us is a fan of the idea of truncating/deleting the table for the reasons stated above. However we could add a warning if the table already exists and bail out early by throwing a more descriptive exception. We could even add a small helper method, so that we start making our update functions more user friendly :)
A follow-up would be welcome.
Comment #87
oriol_e9gIn my system I have fixed the issue adding:
It's a bad practice but works.
Comment #88
tipit commented@longwave Thank you for #82 tip, that works!
I just did: DROP TABLE `taxonomy_term__parent`;
And the update goes as planned.
Comment #89
benjifisherI added a follow-up issue as suggested in #86: #3001205: Make update functions more user friendly.
Comment #91
mark-mackenzie-nexus commentedWe're still experiencing this issue (updating fomr 8.5.8 to 8.6.2) and I believe it boils down to the final check that assigns $sandbox['#finished']. For us (maybe we're weird) the value of the count for the taxonomy_term_hierarchy table is greater than the number of records returned from the join between taxonomy_term_hierarchy and taxonomy_term_data.
I'm going to investigate that a bit further but for all I know, this mismatch is totally normal. Either way, with the current iteration of the code, the upgrade never exists because the check always thinks there's more rows to process.
Any thoughts?
Comment #92
benjifisher@mark-mackenzie-nexus:
This issue is closed, and will not get much attention going forward. Please continue to investigate. When you have as much information as you can get (ideally, enough information to reproduce the problem) open a new issue and reference this one.
Comment #93
patacra commentedI had the same issue updating two websites lately.
To repair the terms after the Drupal console
upexcommand, I set my php.ini to a high max_execution_time and run this in Devel's PHP execute form:This repaired all my vocabularies.
Hope this can help someone else.
Comment #94
pritam.tiwari commentedI have also faced same issue while database update.
#88 Solved the "taxonomy_term__parent" issue " Integrity constraint violation: 1062 Duplicate entry '4-0-0-en' for key 'PRIMARY'" But facing the following issue.
" Call to a member function getConfigDependencyName() on null"
" Update failed: lightning_media_update_8019"
"Update aborted by: lightning_media_update_8019"
"Finished performing updates."
System details:
Lightning Version upgrade from 3.1.7 to 3.2.0.
- Updating drupal/core (8.5.10 => 8.6.9): Loading from cache
Current Drupal version: 8.6.9
Any updates for the issue will be appreciated. Same issue is open on https://www.drupal.org/project/lightning_media/issues/3029107
Comment #95
asherry commentedpatacra: #93 definitely helped me, almost all my vocabularies were broken after the upgrade. Do you know why this script is needed and what exactly is wrong with the upgrade script?
Comment #96
chriscalip commentedError sighted.
How to get PASS this error.
Before doing update taxonomy_update_8502 make sure that {taxonomy_term__parent} is empty.
This particular update is prone to crashes! If you can do command-line to do updates. Command line eg. drush, terminus, drupal-console, etc..
Comment #97
gmangones commented@longwave Thank you for #82 tip, that works!
I just did: DROP TABLE `taxonomy_term__parent`;
So, is necesary delete before apply /update.php.
thanks
Comment #98
nishantkumar155 commentedI am facing this issue while updb , I tried comment #87 it worked for me ,
So providing patch for same .
Comment #99
nishantkumar155 commentedComment #100
wtuvell commentedI hit this problem (taxonomy update #8205) while doing a long-jump update (from 8.5.5 to 8.7.0). The suggestion to DROP TABLE taxonomy_term__parent didn't work for me (because the update didn't recreate the table). Instead, what did work was to first empty the table (DELETE FROM taxonomy_term__parent;), and then the update worked. I can't claim this "really did the right thing" though, because I don't actively use the taxonomy module/feature.
Comment #101
ofrommel commentedSame problem with an update from 8.5.6 to 8.7.1. Deleting all rows from taxonomy_term__parent as in #100 helped and also the taxonomy still seems to work.
Comment #102
drupaldope commentedHello, I think I have run into this problem:
"missing terms in taxonomy tree UIs, even if the corresponding records are available in the taxonomy tables."
The site has been updated to 8.60, 8.6.3, 8.6.4, 8.6.5, 8.6.7 and then 8.6.12 and 8.7.0, 8.7.2...
Problem is, I can't rollback to 8.5 as data has been addded to the site since.
As the correct taxonomy data is present on the terms themselves, is there a way to rebuild the hierarchical data?