The "Is not one of" operator for filters does not appear to be working correctly. I get the same results I would get with the "Is not empty (NOT NULL)" operator. I have observed this problem with text list fields and boolean fields. These are the only two I checked, so it may be happening with other field types.
Here's a little more detail. Suppose I have a text list field with the following possible values:
choice_1
choice_2
choice_3
choice_4
Then I create a view with a filter for that field, with the "Is not one of" operator selected for choice_3. I would expect the view to show me all nodes with values other than choice_3, as well as all nodes with no value selected for that field. Instead what I get is all nodes with a value entered for that field, even if the value is choice_3. The only nodes getting filtered out are those with no value selected for the field.
Comment | File | Size | Author |
---|---|---|---|
#7 | views-1529016-not-in-include-null-values.patch | 962 bytes | ygerasimov |
Comments
Comment #1
onejam CreditAttribution: onejam commentedI'm running Views 7.x-3.3 and i'm also having this same issue.
Comment #2
bunthorne CreditAttribution: bunthorne commentedI am also having the problem with 7.x-3.3.
I have a List text field with 4 check box options (let's call them A, B, C, and D); I added the field as a Filter to select a record that "is not one of" the B value. The view instead returns only returns records that have A, C or D checked; it does not include the records that are empty/null (no box checked)--which is most of the records.
I am unable to find a workaround to use the "is one of" or the empty/not empty options to get to the same results. I need the "is not one of" option to work! The only way to get there would be to add a fifth checkbox value that represents the null value selection, set it as the default, and fix all the data so that I could flip the logic to the "Is one of" type. But I really don't want to go there.
I have tried this several times in two different environments, building and rebuilding views, plenty of cache clearing, etc. Let me know if any more specifics would be helpful.
Comment #3
dawehnerIf you think about how such a query currently looks like, this is not a real wonder:
This joins in the same line multiple times, so a NOT IN will match the other lines at least one time.
I'm not sure at this moment of the early morning how to create proper sql to make it working for you.
Comment #4
bunthorne CreditAttribution: bunthorne commentedFor those of us who don't code and need a logical workaround, I was able to create the desired result by using the "Value is one of (A,C,D)" OR "Value is empty" as a filter combination block--in place of the broken "Value is not one of (B)" logic.
Comment #5
eusonic CreditAttribution: eusonic commented@bunthorne
That's a great solution as long as you always know what the options are. It won't be maintainable if the options change frequently, such as a term reference field.
Comment #6
bunthorne CreditAttribution: bunthorne commentedIs there a patch available?
Comment #7
ygerasimov CreditAttribution: ygerasimov commentedThe idea of attached patch is to add OR condition to include NULL values. Please test.
Comment #8
marblegravy CreditAttribution: marblegravy commentedPatch at #7 tested and working as expected. Thanks ygerasimov.
In my case the issue was that I have an existing site that needed a new field to specify an 'archive' state, but because none of the existing content had the archive field, null values were not being counted and so all of my views that were supposed to just not show 'archived' content (Not one of "Archived"), were showing nothing.
EDIT: As an interim measure bunthorne's solution at #4 works too. Create a Filter Group and create two filters for the target field:
This should work for future values too (so #5 - you should be fine to use this method too)
Comment #9
majorbenks CreditAttribution: majorbenks commented#4 works not for me, because I have multiple choices. (I can have A and B checked, but I do not want to show the node if B is checked, regardless what else is checked)
The patch in #7 is not working for me neither. Propably becauce the multiple choices.
Comment #10
majorbenks CreditAttribution: majorbenks commentedWhatever I try, it is not working. I definetly need a "not in" for "I can have A and B checked, but I do not want to show the node if B is checked, regardless what else is checked".
Comment #11
majorbenks CreditAttribution: majorbenks commentedOuups, sorry I did not see the new update. With 3.5 everything is fine.
Comment #12
bunthorne CreditAttribution: bunthorne commented3.5 appears to have reset the choices for me. I did have to rebuild the filters, however. Several of my views were no longer functioning correctly after the upgrade because of the change to the "is not one of" logic, apparently. No problem--I was using workaround logic anyway, and it needed to be fixed. So I am happy. Thank you for the fix!
Comment #13
ygerasimov CreditAttribution: ygerasimov commentedPlease mark RTBC if you think patch works as expected.
Comment #14
adeb CreditAttribution: adeb commentedDoes anyone know the status of this ? Is the patch in the dev version? (if so it doesn't work for me) I delayed a drupal 6 upgrade way back in 2010 because of this issue, would be awesome to finally upgrade.
(http://drupal.org/node/1129152)
Comment #15
bunthorne CreditAttribution: bunthorne commentedStatus update?
Comment #16
oneiropolos CreditAttribution: oneiropolos commentedI am having the same issue, using Views 7.x-3.6
Comment #17
Gode.Agarunov CreditAttribution: Gode.Agarunov commentedPatch applied on latest version, 3.7, and seems to work without issue.
Comment #18
mattew CreditAttribution: mattew commentedI think this is a major issue because Views does not work as expected and we have to read the query in the Views UI to see the problem ! (the query search for NULL value instead of properly testing the value).
The bug exists on 7.x-3.7 too.
Comment #19
mattew CreditAttribution: mattew commented