Opened 12 years ago
Closed 12 years ago
#29185 closed defect (bug) (fixed)
get_terms with parent set incorrectly hides non-empty terms
| Reported by: | smerriman | Owned by: | boonebgorges |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.1 |
| Component: | Taxonomy | Version: | 3.9.1 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
In #26903, it was reported that there was a bug when get_terms is called with hierarchical=true and parent=0 - it would automatically reset hierarchical to false, and therefore hide parent terms which contained non-empty children.
This was fixed by hardcoding a check for parent=0.
However, this should apply for every other value of parent as well. For example, let's say I had:
- One (0)
- Two (0)
- Three (2)
- Four (3)
- Five (0)
- Six (2)
- Two (0)
Calling get_terms with a parent set to category 'One' will return no terms, while it should.
Attachments (3)
Change History (9)
#3
@
12 years ago
- Keywords good-first-bug removed
landakram and I worked on this for a while at WCSF contributor day. First off, I am a bozo for marking it good-first-bug. Second, I think we have the proper fix in 29185.2.patch, but we need to have some more unit tests that describe the current behavior of 'child_of', 'parent', and 'hierarchical', especially in cases where one overrides another.
#4
@
12 years ago
I wrote some additional unit tests that describe the interplay between child_of, parent, and hierarchical. I used this hierarchy for the tests:
- One
- Two
- Three (1)
- Four
- Five
- Six (1)
- Seven
- Two
Here's what I found:
- When
hierarchical == trueandchild_ofis set, both children and non-empty descendants are returned. In other words, in the hierarchy described, Two, Three, Five, and Six are returned. - When
hierarchical == falseandchild_ofis set, only direct children are returned. In the above hierarchy, the returned array is empty. I wrote another test which the hierarchy so that a post was associated with Seven, and the returned array contained only Seven. - When both
child_ofandparentare set,parenttakes precedent overchild_of.
- When
hierarchical == trueandparentis set, the returned array is empty. This is the bug — it should return Two and Five. - When
hierarchical == falseandparentis set, the returned array is empty. - When
hierarchical == trueand bothchild_ofandparentare set, the returned array is empty. This is the bug — to be consistent with the behavior of 3, it should return Two and Five. - When
hierarchical == falseand bothchild_ofandparentare set, the returned array is empty.
The attached patch includes the unit tests and the fix that boonebgorges and I came up with. When patched, 4 and 5 are fixed (test_hierarchical_parent_get_terms and test_hierarchical_parent_child_of_get_terms respectively).
Now, I can't say whether the existing behaviors make 'sense', but the proposed patch leaves those behaviors intact while fixing this bug :)
#5
@
12 years ago
- Keywords needs-unit-tests removed
- Milestone Awaiting Review → 4.1
- Owner set to
- Status new → accepted
Thanks for the additional tests, landakram. The behavior of these parameters is pretty confusing, and it's extremely valuable to have these tests to demonstrate a bit more clearly how they work together.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
If I understand correctly, then for any value of
parent,hierarchicalshould not be automatically reset, since the cases that were already being excluded were whenparent == ''and whenparent == 0.I attached a patch which removes the value checks for
parentthere entirely. I also added a test for the setup described above, which verifies that the patch has the intended behavior.Apologies for uploading the patch with the wrong extension — I'm not sure how to remove it!