Hi,

The exposed filter Content : has taxonomy terms (with depth) seems to be broken. [EDIT : does not bring back unpublished nodes.]

Steps to reproduce:

Create a Vocabulary with at least two levels as such :

Parent 1
Parent 2
- Child 2.1
- Child 2.2
Parent 3

Assuming that:
- Some nodes can be directly referencing parent terms like "Parent 1" or "Parent 3".
- Some nodes can be directly referencing Children terms like "Child 2.1"
- There cannot be nodes referencing parent terms that have children terms. Ex : there cannot be nodes referencing "Parent 2".
- The Exposed Filter is of type Content : has taxonomy terms (with depth) using a depth value of 1.

Expected behavior:
If the exposed filter is set to "Parent 1", all/only nodes referencing "Parent 1" should be retrieved
If the exposed filter is set to "Child 2.1" all/only nodes referencing "Child 2.1" should be retrieved
If the exposed filter is set to "Parent 2" all/only nodes referencing "Child 2.1" and also "Child 2.2" should be retrieved

Actual behavior:
- Leaving the exposed filter to "- Any -" brings back all results as expected
- Choosing any other value of any level brings back no results.

I actually tried on several Drupal installations with different versions of Views installed.
Is this working for anyone?

EDIT [ #4
Found it! The bug happens when you try to display unpublished nodes only.
On a clean install, follow the steps on #1 and finally add a filter Content : Published (No).
Obviously you also need to unpublish your nodes...
]

Comments

Mołot’s picture

"not working at all for me" is very vague term that makes it quite impossible to help here.
Could you describe experienced behavior just the way you described expected one? Or do you simply meant that filtering is ignored and you always get all nodes anyway?

And maybe include sample data and exported view that, imported to a clean Druapl+Views installation, allows to recreate your bug?
For me filtering by taxonomy always worked quite as expected.

nicolas bouteille’s picture

Sorry. Edited my first post to add the Actual behavior. Will now see if I can reproduce this on a clean Drupal + Views install.

nicolas bouteille’s picture

Category: bug » support

Ok it works on a clean install... sorry for calling this a bug report. Switching back to support request.
What info could I provide you with so that you could help me find out what's wrong in my config and causing this not to work?

nicolas bouteille’s picture

Category: support » bug

Found it! The bug happens when you try to display unpublished nodes only.
On a clean install, follow the steps on #1 and finally add a filter Content : Published (No).
Obviously you also need to unpublish your nodes...

Mołot’s picture

Congratulations :)

So long story short unpublished nodes are treated like not belonging to any taxonomy term there?

nicolas bouteille’s picture

Title: Exposed Filter Content : has taxonomy terms (with depth) seems to be broken. » Exposed Filter Content : has taxonomy terms (with depth) does not bring back unpublished nodes

Yes. But it works for simple taxonomy exposed filters. Only not working with filters with depth.
Updating title.

Mołot’s picture

Will see if I can patch this easily. Shouldn't be hard when we have a comparison.
Could you paste the very SQL? With -Any- and with selection? That would make it easief for me to find that part of code (I'm not a part of viwews team, you know, just a one who happened to need them bug-free)

Edit: OK, forget it, views_handler_filter_term_node_tid_depth.inc
But I can't see any point that would refer to published nodes or unpublished ones. So I guess I'd really like to see your SQLs anyway. And what SQL engine and version you are using? If MySQL, are your table MyISAM, InnoDB or mox of those? Only joins added for depth are around line 80 to 95, and they are simple and reasonable. And seems to work for me.
Or maybe current GIT version works already? Consider $ git clone --recursive --branch 7.x-3.x http://git.drupal.org/project/views.git

nicolas bouteille’s picture

Here is the SQL generated when - Any - is selected. All nodes even unpublished are brought back.

SELECT node.nid AS nid
FROM 
{node} node
WHERE (( (node.type IN  ('test_content_type')) ))

Here is the SQL generated when a Parent term with children is selected or when a Child term is selected (the SQL is the same). Unpublished nodes are forgotten.

SELECT node.nid AS nid
FROM 
{node} node
WHERE (( (node.type IN  ('test_content_type')) AND (node.nid IN  (SELECT tn.nid AS nid
FROM 
{taxonomy_index} tn
LEFT OUTER JOIN {taxonomy_term_hierarchy} th ON th.tid = tn.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th1 ON th.parent = th1.tid
WHERE ( (tn.tid = '2') OR (th1.tid = '2') ))) ))

I am using a MySQL database with innoDB tables.
For the last part I don't know how to use Git yet :(

Mołot’s picture

How to use GIT: On linux: install it, open console, cd to your modules directory and just paste the command (without $, $ means it's a shell command of a non-root user). On windows install http://msysgit.github.io/ run GitBASH and do the same ;) and then consider git-aware IDE (NetBeans, Eclipse, Zend, whatever)

And your problem seems not views-related, http://drupal.org/node/962664 this issue shows it's bug in core - unpublished nodes are simply ignored by functions that operate on {taxonomy_index} and it seems it's by design.

Mołot’s picture

Posted by ngmaloney on November 8, 2010 at 7:12am

bangpound, you are correct, It is possible to query by field value in views. One of the drawbacks is, by default, you can only query by TID, not Term Name. Having the values in the taxonomy_index table gets around this issue. The other way is to write a php argument handler. The patched method seems like a "cleaner" implementation when doing look ups by Term Name.

Seems you need to write your own argumen handler for now. One that will use field directly, without the index table.

You can pretty much steal code from views_handler_filter_term_node_tid_depth.inc to do it, just wrap it in a module.

nicolas bouteille’s picture

Thank you for your great help.
This is starting to be a bit difficult for me but I'm sure I will understand it in the end :)

Mołot’s picture

I still think there is an irritating inconsistency. Taxonomy uses {taxonomy_index} as an cache for published nodes only. Views use this table as an taxonomy-node join table, no matter pubilshed or not. Taxonomy team claims it's views bug, view guys claim it's taxonomy's problem.

Why can't they cooperate and either stop using this table in views or start filling it for all nodes in taxonomy? I expected more from Drupal teams.

gan_drupal’s picture

@Nicolas - Thanks. Actually I'm also trying to get the same behavior. But not able to get the below expected behavior:

"If the exposed filter is set to "Parent 2" all/only nodes referencing "Child 2.1" and also "Child 2.2" should be retrieved"

Meant, if i select Parent 2, my result out of it is nothing.

How do i get this using Views + Drupal 6 ? Can anyone help on this ?

nicolas bouteille’s picture

this post was not related to the original problem and has been moved here https://drupal.org/node/2116645

gan_drupal’s picture

Thanks a lot @Nicolas. I got it now.

What i was trying now is, when i click the checkbox of parent 2.1 and hit on search button i got the expected result, when i try to search for parent 2.2 also i got the result.

Now what i need is, when i click on parent 2, i got the result with both parent 2.1 and 2.2, but the checkboxes are not checked for parent 2.1 and 2.2.

I want both the checkboxes to be checked when i click on parent 2 for search. In the same way, if i check both parent 2.1 and parent 2.2, then parent 2 should also be checked automatically. Is it possible ? please advice.

gan_drupal’s picture

Issue summary: View changes

Added Actual behavior

nicolas bouteille’s picture

Ok I created a new issue for your request and I will delete my previous post so that this issue remains related to its original problem.
https://drupal.org/node/2116645

gan_drupal’s picture

Anyway thanks for your advice @Nicolas. Much Appreciated !!!

gan_drupal’s picture

Issue summary: View changes

adding info on the real problem

rimibhagat’s picture

This Issue still persists with Drupal 8 too.
On unpublished content the taxonomy filter of "has taxonomy with depth" doesn't work.
Any Update on this?