Closed (duplicate)
Project:
Drupal core
Version:
9.5.x-dev
Component:
taxonomy.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
28 Mar 2018 at 07:45 UTC
Updated:
2 Sep 2026 at 13:57 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
wengerkHello @tonifisler !
As you suggest, I also think it's due to the cached previous weight. As we can see, when you click on the button "Reset to alphabetical" you still see the previous weight instead of 0 (the button will reset every term in the vocabulary to weight=0).
I think it's because the
Drupal\taxonomy\TermStorage::resetWeights()alter the database without refreshing/releasing the entity cache.I'm working into a patch that fix this using the internal reset cache.
Comment #3
wengerkHere is my first drafted patch ! Let's test it via testbot !
Comment #4
wengerkComment #5
borisson_This needs a test that proves that this behavior is now correct, and that it was broken before.
Comment #6
wengerkAs suggested by @borisson_, I created a tests coverage for this issue.
On my research, I found this coverage was already partially done by
Drupal\taxonomy\Tests\TermTest::TaxonomyTermReorderTestbut the coverage reset the cache manually, so, of course, it works perfectly.One more things, the previous coverage was made with SimpleTest - so I decide to update it as BrowserTest. I remove
Drupal\taxonomy\Tests\TermTest::TaxonomyTermReorderTest& create a new TaxonomyTestBase class for this coverageDrupal\Tests\taxonomy\Functional::TaxonomyTermReorderTest.In the new coverage, I assert the UI is up-to-date when using reordering & I also asserts the non-usage of cached weight (the purpose of this issue).
I post here 2 patches, one that should fail (it contains the new coverage w/o the cache fix from #3) & a second patch that should work.
Let's try it with the Testbot.
PS: I also reroll the code for Drupal 8.6.x
Comment #7
wengerkComment #8
borisson_This looks good, removing the needs test tag. I'm not sure if this issue violates the scope, because it now does 2 things. The testbot does seem to agree with this though. I couldn't get git to recognize this with --color-words to figure out what exactly changed between the 2 tests.
I did find a couple of things though, so nitpicks ahead.
This doc comment can be replaced with
{@inheritdoc}
Should we reset the cache here?
I think we should remove the resetCache here.
Comment #9
wengerkThanks for the review quick review !
I will work on 1 & 2 to fix this asap.
About 3, yes we have to "reset the cache manually" here because we already load the terms previously -
loadMultiple- so the already loaded terms contains old weight, parents, depth & it's in the cache.loadTreeuse an internal cache so the terms aren't loaded anymore but just retrieve from it.By precautions I try to remove those both, but the test fail on the following lines (also those 2 resets were already in the code of the initial SimpleTest).
Finally, I know it does 2 things, but it's necessary to complete this issue. Decoupling this test from the old SimpleTests is quite logical & it doesn't create any technical debts, it's the only test that exists about reordering terms so nothing else is impacted (it's not a partial porting of similar tests SimpleTest/BrowserTest). What do you think ?
Comment #10
borisson_Awesome, your explenation makes sense. I agree about the move to BTB.
Comment #11
wengerkAs suggested by borisson_ in #10
1. Removed the whole
public static $modulesbecause it's already done by inherited ClassTaxonomyTestBase.2. Remove unnecessary clear-cache (mistake I made during coding this new Class).
Comment #12
wengerkComment #14
wengerkMove to need review again, bot move it to - need works for failing tests - but it was on purpose :).
Comment #16
wengerkThe tests works as design. Move as Need Review.
Comment #18
wengerkComment #19
Piyush_Rai commentedwengerk Working fine as i tested.
Comment #20
catchWe should be able to clear the entity cache without saving the entity here, i.e. $this->entity->resetCache().
Comment #21
vj commentedUpdated patch as suggested by catch. Used termStorage instead of entity to reset cache.
Comment #22
wengerkMany thanks @Vj for your help ! I'm a bit concern about
termStorageI think it will remove the cache of the whole storage instead of this vocabulary only. So it will invalidate internal cache of others taxonomies. I think it could be a problem on big web-applications (performances issues as we reset the cache).Also, I think it was a mistake but you remove the
testTermReorder? I would suggest to keep the coverage.@catch, I try to use
resetCachebut it doesn't exists onVocabulary.I try the following ways & here the results:
Vocabulary::savecode from #11 - the test PASSVocabularyStorage::resetCachewith & without the entity as parameter - the tests FAILTermStorage::resetCachecode from #21 without params - the test PASSWhat is the best approach then ? it seems only
TermStorage::resetCache&$this->entity->save();works on our case - which is the best approach then ?Comment #23
wengerkComment #24
wengerkHere the patch from #21 with the initial coverage.
I upload 2 interdiff to show that I only add from #21 the inital coverage (which was on #11).
We still need to choose - I think - a better approach to reset the cache see #22. @catch any idea ?
Comment #25
wengerkComment #26
vj commentedoops @wengerk Sorry it was removed by mistake
Comment #27
lfilipov commented@wengerk This patch is quite useful. We had the same issues. Sadly we are using BLT which has an issue with Drupal core which is above 8.5.6 and we had to fix this without applying the patch.
I will add our solution just in case someone is in our case:
@wengerk Really useful patch!
Comment #28
tonifisler commentedThe patch needs to be rerolled for 8.6.10.
Comment #29
Asacolips commentedRerolled for 8.6.10.
Comment #30
tonifisler commentedComment #33
wengerkHere a reroll for 8.9.x
Comment #34
wengerkAdd the tag Amsterdam as I work on this issue during the DrupalCon 2019 in Amsterdam.
Comment #35
rachel_norfolkretagging
Comment #37
gido commentedFixing the deprecation notice in the test.
Comment #38
gido commentedComment #39
alexrayu commentedConfirmed the issue. #37 resolved the issue.
UPD: There is a side effect. When the list is reset to alphabetical order, weight values are all assigned zeros, but then if the list is saved, strange weights get assigned, and the list order is garbled.
Comment #40
alexrayu commentedRelated issues:
https://www.drupal.org/project/drupal/issues/2928661
https://www.drupal.org/project/drupal/issues/2860309
Comment #41
alexrayu commentedDebugged the issue. The alphabetical order is a separate bug, this issue just uncovers it but not directly related.
I would suggest reviewing it separately and working on the alphabetic order sorting bug in it's corresponding ticket. https://www.drupal.org/project/drupal/issues/2928661
Comment #42
krzysztof domański1. It should be removed.
* @group failingtest2. Instead of this order:
Let's separate the code thematically:
3. Once created, terms will be sorted alphabetically.
Let's set the order of terms randomly. For example:
Comment #43
krzysztof domańskiRe #22. Rights. We can fix it. The cache will reset for the entities with the given ids:
Comment #44
mschudders commentedTook patch #37 added #43 and added Cache tag invalidation.
Why?
We had a view listing the terms.
However
reset cache entries for
values:taxonomy_term:**We needed:
taxonomy_term:**without the "values".
Now my questions remains is this expected behaviour and is this extra Cache invalidation necessary or is the resetCache faulty?
Thanks
Patch attached.
Comment #48
kriboogh commentedIn stead of doing a loadtree we should use a entity query to just fetch the ids. This way it doesn't load all terms in memory. Loadtree can be a problem when having a huge amount of terms in a vocabulary (+10k terms).
So #43 should be:
Comment #49
kriboogh commentedReroll to 9.2.0 stable.
Comment #50
mschudders commentedreroll of #44
Now my questions remains is this expected behaviour and is this extra Cache invalidation necessary or is the resetCache faulty?
Thanks
Patch attached.
Comment #52
mschudders commentedreroll 9.3.0
Comment #54
antoniya commentedThis issue looks like a duplicate of #2928661: Reordering taxonomy terms after "Reset to alphabetical" yields incorrect results upon save?
Comment #55
antoniya commentedComment #56
alexpottI'm closing this as a duplicate of #2928661: Reordering taxonomy terms after "Reset to alphabetical" yields incorrect results upon save
Comment #57
yogesh_kambari commentedPatch for drupal version 10.5.0.