I was trying to find a list of open D8 criticals that were not tagged "beta blocker":
https://drupal.org/project/issues/search/drupal?status[]=Open&priorities...<>&issue_tags=beta+blocker
This shows me a list of all open D8 criticals that have a tag. Any tag. It is the expected behavior of the "not empty" operator.
I figured this out because the only issue that is filtered out is #2110863: Support open_basedir, which is one of the few D8 issues that has no tags at all.
The "empty" and "not empty" operators are broken unless you manually pass an issue tag through the URL:
Shows all issues: https://drupal.org/project/issues/search/drupal?issue_tags_op=empty
Filters correctly, unreachable via UI: https://drupal.org/project/issues/search/drupal?issue_tags_op=empty&issu...
The "is one of" and "is all of" seem to work fine.
| Comment | File | Size | Author |
|---|---|---|---|
| #22 | interdiff.txt | 5.49 KB | tim.plunkett |
| #22 | 2188165-empty-22.patch | 6.79 KB | tim.plunkett |
| #9 | 2188165-9.views-taxonomy-tid-handle-empty.patch | 1.61 KB | dww |
| #16 | 2188165-vdc-16.patch | 1.66 KB | tim.plunkett |
| #20 | 2188165-empty-20-PASS.patch | 7.54 KB | tim.plunkett |
Comments
Comment #1
drummDrupalorg is the best place to triage this. The SearchAPI-powered Views have not made it into Project Issue yet. Likely, this could be a problem in SearchAPI.
Comment #2
xjmComment #3
webchickThis is definitely a pain for prepping for things like issue triage, sprints, etc.
I also found #1529016: "Is not one of" filter operator broken but from #1 it sounds like we might not be using Views for this after all?
Comment #4
xjmClosed #2244721: NOT IN filter on issue search does not work as a duplicate of this issue. That issue had the "d.o hitlist" tag which I've added here for parity.
Comment #5
yesct commentedComment #6
yesct commentedComment #7
jesss commented#477984: CCK field is empty/not empty filter doesn't work when exposed in the Views issue queue sounds like it's describing a similar issue. There's a recent patch against the 7.x-dev branch.
Comment #8
jesss commentedThe root of this appears to be a long-standing bug in Views that ignores empty/not empty exposed filters if a value isn't passed as well. (See #477984: CCK field is empty/not empty filter doesn't work when exposed, referenced above.)
I set this up on a clean install and discovered the following:
When the filter is set to display all items where the tags are empty (TID is NULL), the query produced by views_plugin_query_default() looks like this:
Note that it is completely ignoring the exposed filter settings.
If you also somehow include a term in your query (for example, TID is NULL and TID = beta blocker), the query instead looks like this:
So, somewhere in Views, there is logic checking that an exposed filter has a value before including that filter in the query. But, since an empty/non-empty filter doesn't have a value, it doesn't pass the logic check, so doesn't get included when the query is built.
Additionally, within the filter handler there is
$this->operator, which is supposed to contain a string like 'or', 'and', or 'empty'. In all cases, it is just 'or'.The patch posted to #477984 doesn't appear to have any affect on the issue.
Comment #9
dwwI sat with tim.plunkett for a bit @ the DrupalCon LA sprint to look into this. Attached patch isn't beautifully elegant in all ways, but it fixes the problem. I'll try to summarize:
- Generally, Views makes all sorts of assumptions that if a filter has no input, it should be ignored.
- There's a mechanism to over-ride this, in the form of the
accept_exposed_input()method. If that returns TRUE, Views assumes that the handler has all the input it needs to be included in the query.- Only all the way up in
views_handler_filter::accept_exposed_input()(nearly the base of the class hierarchy) do filters that include an operator argument set$this->operator.- views_handler_filter_in_operator is the class that adds the EMPTY vs. NOT EMPTY choices to the possible operators.
- However, views_handler_filter_term_node_tid (the child class for filtering by taxonomy term), has a clause inside accept_exposed_input() that is bailing out early if there's no value, forgetting about the possibility of the EMPTY and NOT EMPTY operator choices.
So, it's a bit ugly, but this patch is adding the code to properly set
$this->operatorinsideviews_handler_filter_term_node_tid::accept_exposed_input()early enough for us to use that knowledge to return TRUE if we're dealing with one of the (NOT)? EMPTY operators, since we don't need any further input beyond the operator.It seems evil and wrong that properly initializing
$this->operatoris a side effect of this function that's also being used to determine if we have enough input yet. :/ But a complete re-design of this system is out of scope for this issue. Sinceviews_handler_filter_term_node_tid::accept_exposed_input()is currently where the bug lives (returning FALSE when it shouldn't), that seems like an acceptable level to fix this.Thoughts/objections/alternatives?
Thanks!
-Derek
Comment #12
dwwNote: fixing this on d.o will actually require fixing SearchAPI, since that's what powers the production issue queue views. I just uploaded an equivalent patch to that queue:
#2489882: Taxonomy views filter doesn't handle is/not empty operator
@jesss: If you wanted to test that patch to search api on the dev site you were using, that'd be fantastic. Please let us know if that's possible.
Thanks!
-Derek
Comment #14
dwwPlease ignore testbot failures for this patch. See #2273481: Contrib PSR-4 PHPUnit tests are not picked up by PIFR for more.
Comment #15
tim.plunkettThis is really not ideal, but without refactoring how $this->operator is populated all across views, we're stuck with this in D7.
Committing this, and moving to D8. Thanks so much @dww, @jesss, @tvn, @dawehner, and @drumm!
Comment #16
tim.plunkettRerolled.
Comment #17
tvn commentedComment #18
tvn commentedhooray!
Comment #19
dwwHooray indeed! However, this doesn't actually affect d.o. :) The one we really need to deploy is actually #2489882: Taxonomy views filter doesn't handle is/not empty operator.
Comment #20
tim.plunkettWhew. Those tests were not fun to write.
Comment #22
tim.plunkettCleaning up the test a bit, it was full of unnecessary things I copied from other places in order to get it working.
Comment #23
tim.plunkettComment #24
dawehnerDid some form of life review earlier already.
Great improvements!
Comment #25
jibranThose tests were not fun to write.Use CSS selector instead of xpath then. :PComment #26
dawehnerI think the actual tricky part is to setup all that stuff.
Comment #29
yesct commentedweird, that was rtbc, and was *still showing green*. not sure why that failed message was added in #27. retested.
Comment #30
yesct commentedgreen. back to rtbc then.
Comment #31
tim.plunkettAs this was fixed in D7 Views (and in Search API Views!), this is now a regression.
Comment #32
webchickOh, yes, please let's not hit this bug again in 4 years.
Committed and pushed to 8.0.x. Thanks!