Problem/Motivation
The original report in this issue was about incorrect validation on adding grouped filter by date field with "Is empty(NULL)" or "Is not empty(NULL) operator:
steps to reproduce the problem:
1. edit view, add a filter which field type is date
2. select "Expose this filter to visitors, to allow them to change it"
3. select "Grouped filters"
4. in the group options, select "Is empty(NULL)" or "Is not empty(NULL) as operator
5. input a label for this options
6. Click "Apply (all displays)" button, will cause this issue: "The value is required if title for this item is defined. "
The problems:
"Is empty(NULL)" or "Is not empty(NULL) operator do not need input value, and could not input value, but the group options validator will check it, so could not setup the label for date filter group options.
However, it's not possible to reproduce at this moment. See #8 and #16.
Given the test coverage for mentioned operators is missing, there is a proposal to add extra test coverage for exposed date filters operators, which are using different values. It'll prove that available operators pass the validation and work as expected.
Proposed resolution
Add additional asserts to check that date filter operators, that uses different value properties.
Here is a list of possible variations:
| Operators | Expected values |
|---|---|
<, <=, =, !=, >=, > |
<code>value |
between, not between |
<code>min, max |
empty, not empty |
- |
It should be enough to cover at least 1 operator from each row.
| Comment | File | Size | Author |
|---|---|---|---|
| #46 | 2636086-31.patch | 5.93 KB | quietone |
| #46 | interdiff-31-39_0.txt | 639 bytes | quietone |
| #39 | reroll_diff_38-39.txt | 1.32 KB | ravi.shankar |
| #39 | 2636086-39.patch | 5.92 KB | ravi.shankar |
| #38 | 2636086-38.patch | 5.91 KB | spokje |
Issue fork drupal-2636086
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments
Comment #2
jian he commentedComment #4
dawehnerCan't we use
\Drupal\views\Plugin\views\filter\NumericFilter::operatorsin order to figure out how many parameters this specific operator needs? This would feel just a little bit nicer :)Comment #8
sweetchuckI couldn't reproduce the described bug.
There is no "The value is required if title for this item is defined." error message when I choice the "Is empty" or "Is not empty" filters as grouped options with custom label.
I think this problem was fixed as a part of another issue.
So I recommend to close this issue with "Closed (outdated)" or "Closed (cannot reproduce)"
However find 2 other strange things that could be a separated issue (if not reported already)
Unnecessary descriptions in the "Value" column
Does not make any sens this description for a filter which does not use any user input (is_empty, is_not_empty)
Value type
The grouped "Is empty" and "Is not empty" are ignored
The WHERE clause of the generated SQL statement does not contains any filter for a date field.
Comment #13
liquidcms commentedI get this same error when switching from an "is equal to" to an "in between" operator. When switching i now get 2 fields to fill in and even though both are filled in, i get both fields reported as in error.
seems like this patch may be focused on the "Is empty" and "Is not empty" operators; so probably not targeting the core issue.
Comment #16
matroskeenI'm not able to reproduce the issue on latest 9.4.x version following the steps mentioned in the issue summary.
I tried different operators that require different set of values - it works as expected.
I didn't dig too much, but those 2 issues seemed very similar, so probably it was fixed there:
To prove this, I'm attaching a merge request with the test coverage for Date filter with all possible variations. Each of the tested operators accepts different values and it'll prove that the issue no longer exists.
By the way, when I was there, I noticed that we have multiple functional tests for views date filter:
\Drupal\Tests\datetime\Functional\DateFilterTest\Drupal\Tests\datetime\Functional\Views\FilterDateTest\Drupal\Tests\views\Functional\Handler\FilterDateTestI think we should merge 3 into 1, and I tend to keep #2, which I used in the merge request. I think it should be done in a separate issue, but I need to confirm with Len.
Comment #17
matroskeenUpdating the issue summary and going to dig into existing tests.
Comment #18
matroskeenUpdating again and moving to "Needs review".
Comment #19
matroskeenAdding possible operator variations to the IS.
Comment #20
lendudeThanks, this looks great.
Really good to get this extra coverage because grouped filters tend to be fragile and under-tested.
Since this is Views + dates I've kicked of postgres and sqlite tests too, RTBC'ing assuming those come back green too.
Comment #21
matroskeenIt still applies to 9.4.x and 10.0.x.
I'm changing the branch and uploading a patch (there is no diff) to show that it applies to both versions.
Comment #23
matroskeenRestoring the status because of random test failure.
Comment #24
larowlanThis looks good to me, we're in commit freeze this week, but I'll revisit it later in the week
Comment #27
larowlanCommitted and pushed to 10.0.x
As this is adding extra test coverage and there is little risk of disruption, backported to 9.4.x and 9.3.x as well to keep the branches consistent.
Comment #29
larowlanThis broke HEAD, so I reverted it.
See https://www.drupal.org/pift-ci-job/2342417 for details
Comment #30
larowlanComment #31
spokjeLooks like this collided with #3264122: Move all non migration aggregator tests to the module in preparation of removal in d10 which changed the signature of
Drupal\Tests\datetime\Functional\Views\FilterDateTest::setUp().Attached patch should apply to
10.0.x-devand9.4.x-devand make PHPStan happy.I've added a raw diff, because patch #21 is in a bit of an awkward format. Basically the only change between #21 and #31 is this bit:
Comment #32
spokjeLet's take this back from the top ->
10.0x.-dev.Comment #33
spokjeComment #34
matroskeen@Spokje thanks for pointing at #3264122: Move all non migration aggregator tests to the module in preparation of removal in d10 - it explains why it wasn't caught by the test bot.
If you're curious, I was using GitLab generator: https://git.drupalcode.org/project/drupal/-/merge_requests/1448.patch
The re-roll is pretty straightforward. I would RTBC if I could :)
Comment #35
lendudeWas going to say the same thing I did in #20, awesome stuff, thanks all!
Comment #36
larowlanThis doesn't apply clean to 10.x anymore
error: patch failed: core/modules/datetime/tests/src/Functional/Views/FilterDateTest.php:142
error: core/modules/datetime/tests/src/Functional/Views/FilterDateTest.php: patch does not apply
I tried a 3-way apply but that failed too.
Comment #37
spokjeComment #38
spokjeThis time we were derailed by #3269517: Datetime and Datetime Range tests should not rely on Classy.
The attached patch should pass for
10.0.x-dev.Comment #39
ravi.shankar commentedAdded reroll of patch #38 on Drupal 9.3.x.
Comment #40
spokjeSo for 10 and 9.4 -> #38
Unsure if #3269517: Datetime and Datetime Range tests should not rely on Classy was backported to 9.3, if not #31 might still apply. Otherwise #39 might be the one.
Comment #41
lendudeThe fail in #39 is unrelated.
Back to green, back to RTBC
Comment #43
larowlanCommitted 248d012 and pushed to 10.0.x. Thanks!
Backported to 9.4.x
It would be good to keep 9.3.x consistent here too, can we get a version that applies to 9.3.x
Comment #44
spokjeSo...
both patches #31 and #39 apply and pass tests on
9.3.x-dev(The 1 fail on #39 is a random one).Since #3269517: Datetime and Datetime Range tests should not rely on Classy wasn't backported to
9.3.x-dev, I think #31 is the most clean way to go?Comment #45
catchMoving back to RTBC for #31.
Comment #46
quietone commentedThis is now testing the patch in #38 on 10.0.x instead of a patch for 9.3.x. In #44 @Spokje, thinks the patch to use is the one from #31 so I am re-uploading that so tests run on that. The patch in #39 also applies to 9.3.x, so I am uploading a diff between #31 and #39 to help those who know this work.
Keeping this at RTBC because no changes were made to the patch from #31. Hope this helps.
Comment #47
larowlanBackported, thanks!