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. "
issues
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.

Issue fork drupal-2636086

Command icon 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

jian he created an issue. See original summary.

jian he’s picture

Status: Active » Needs review
StatusFileSize
new975 bytes

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

Status: Needs review » Needs work
+++ b/core/modules/views/src/Plugin/views/filter/Date.php
@@ -111,7 +111,7 @@ protected function buildGroupValidate($form, FormStateInterface $form_state) {
-      if (empty($group['remove'])) {
+      if (empty($group['remove']) && !in_array($group['operator'], array('empty', 'not empty'))) {

Can't we use \Drupal\views\Plugin\views\filter\NumericFilter::operators in order to figure out how many parameters this specific operator needs? This would feel just a little bit nicer :)

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

sweetchuck’s picture

Status: Needs work » Needs review
Issue tags: +Drupalaton 2017

I 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

  • A date in any machine readable format. CCYY-MM-DD HH:MM:SS is preferred.
  • An offset from the current time such as "+1 day" or "-2 hours -30 minutes"

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.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

liquidcms’s picture

I 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.

Matroskeen made their first commit to this issue’s fork.

matroskeen’s picture

Version: 8.9.x-dev » 9.4.x-dev
Issue tags: +Bug Smash Initiative
Related issues: +#2865344: Exposed date filters 'empty' and 'not empty' are broken

I'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:

  1. \Drupal\Tests\datetime\Functional\DateFilterTest
  2. \Drupal\Tests\datetime\Functional\Views\FilterDateTest
  3. \Drupal\Tests\views\Functional\Handler\FilterDateTest

I 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.

matroskeen’s picture

Title: grouped date filters issue: The value is required if title for this item is defined. » Add/refactor test coverage for views date filters
Category: Bug report » Task
Issue summary: View changes
Status: Needs review » Needs work

Updating the issue summary and going to dig into existing tests.

matroskeen’s picture

Title: Add/refactor test coverage for views date filters » Add extra test coverage for operators of views date filters
Issue summary: View changes
Status: Needs work » Needs review

Updating again and moving to "Needs review".

matroskeen’s picture

Issue summary: View changes

Adding possible operator variations to the IS.

lendude’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, 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.

matroskeen’s picture

Version: 9.4.x-dev » 10.0.x-dev
StatusFileSize
new9.59 KB

It 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.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 21: 2636086-21.patch, failed testing. View results

matroskeen’s picture

Status: Needs work » Reviewed & tested by the community

Restoring the status because of random test failure.

larowlan’s picture

This looks good to me, we're in commit freeze this week, but I'll revisit it later in the week

  • larowlan committed 428f586 on 10.0.x
    Issue #2636086 by Matroskeen, jian he, Sweetchuck, dawehner, Lendude:...

  • larowlan committed f1aad3c on 9.3.x
    Issue #2636086 by Matroskeen, jian he, Sweetchuck, dawehner, Lendude:...
  • larowlan committed daa91bc on 9.4.x
    Issue #2636086 by Matroskeen, jian he, Sweetchuck, dawehner, Lendude:...
larowlan’s picture

Version: 10.0.x-dev » 9.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 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.

  • larowlan committed fb6c094 on 10.0.x
    Revert "Issue #2636086 by Matroskeen, jian he, Sweetchuck, dawehner,...
  • larowlan committed 1ee6c36 on 9.3.x
    Revert "Issue #2636086 by Matroskeen, jian he, Sweetchuck, dawehner,...
  • larowlan committed 2fbd9f7 on 9.4.x
    Revert "Issue #2636086 by Matroskeen, jian he, Sweetchuck, dawehner,...
larowlan’s picture

Status: Fixed » Needs work

This broke HEAD, so I reverted it.

See https://www.drupal.org/pift-ci-job/2342417 for details

larowlan’s picture

Running PHPStan on changed files.
PHP Fatal error:  Declaration of Drupal\Tests\datetime\Functional\Views\FilterDateTest::setUp($import_test_views = true): void must be compatible with Drupal\Tests\views\Functional\ViewTestBase::setUp($import_test_views = true, $modules = [...]): void in /home/rowlands/git/core/drupal/core/modules/datetime/tests/src/Functional/Views/FilterDateTest.php on line 68
Fatal error: Declaration of Drupal\Tests\datetime\Functional\Views\FilterDateTest::setUp($import_test_views = true): void must be compatible with Drupal\Tests\views\Functional\ViewTestBase::setUp($import_test_views = true, $modules = [...]): void in /home/rowlands/git/core/drupal/core/modules/datetime/tests/src/Functional/Views/FilterDateTest.php on line 68

PHPStan: failed
spokje’s picture

StatusFileSize
new5.93 KB
new5.59 KB

Looks 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-dev and 9.4.x-dev and 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:

 --- a/core/modules/datetime/tests/src/Functional/Views/FilterDateTest.php
 +++ b/core/modules/datetime/tests/src/Functional/Views/FilterDateTest.php
 @@ -7,7 +7,7 @@
@@ -57,8 +48,8 @@
     */
 -  protected function setUp(): void {
 -    parent::setUp();
-+  protected function setUp($import_test_views = TRUE): void {
-+    parent::setUp($import_test_views);
++  protected function setUp($import_test_views = TRUE, $modules = ['views_test_config']): void {
++    parent::setUp($import_test_views, $modules);
spokje’s picture

Version: 9.3.x-dev » 10.0.x-dev

Let's take this back from the top -> 10.0x.-dev.

spokje’s picture

Status: Needs work » Needs review
matroskeen’s picture

@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.

because patch #21 is in a bit of an awkward format

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 :)

lendude’s picture

Status: Needs review » Reviewed & tested by the community

Was going to say the same thing I did in #20, awesome stuff, thanks all!

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

This 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.

spokje’s picture

Assigned: Unassigned » spokje
spokje’s picture

StatusFileSize
new1.66 KB
new5.91 KB

This 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.

ravi.shankar’s picture

StatusFileSize
new5.92 KB
new1.32 KB

Added reroll of patch #38 on Drupal 9.3.x.

spokje’s picture

Status: Needs work » Needs review

So 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.

lendude’s picture

Status: Needs review » Reviewed & tested by the community

The fail in #39 is unrelated.

Back to green, back to RTBC

  • larowlan committed 248d012 on 10.0.x
    Issue #2636086 by Matroskeen, Spokje, jian he, ravi.shankar, larowlan,...
  • larowlan committed ebc14e6 on 9.4.x
    Issue #2636086 by Matroskeen, Spokje, jian he, ravi.shankar, larowlan,...
larowlan’s picture

Title: Add extra test coverage for operators of views date filters » [Backport] Add extra test coverage for operators of views date filters
Version: 10.0.x-dev » 9.3.x-dev
Assigned: spokje » Unassigned
Status: Reviewed & tested by the community » Patch (to be ported)

Committed 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

spokje’s picture

Status: Patch (to be ported) » Needs review

So...

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?

catch’s picture

Status: Needs review » Reviewed & tested by the community

Moving back to RTBC for #31.

quietone’s picture

StatusFileSize
new639 bytes
new5.93 KB

This 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.

larowlan’s picture

Title: [Backport] Add extra test coverage for operators of views date filters » Add extra test coverage for operators of views date filters
Status: Reviewed & tested by the community » Fixed

Backported, thanks!

  • larowlan committed fbfc240 on 9.3.x
    Issue #2636086 by Matroskeen, Spokje, jian he, ravi.shankar, quietone,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.