In the exposed filter enter a search string in an invalid format e.g. try: lun 2018-04-27. The following error should occur:
<em class="placeholder">Exception</em>: DateTime object not set. in <em class="placeholder">Drupal\Component\Datetime\DateTimePlus->__call()</em> (line <em class="placeholder">355</em> of <em class="placeholder">core/lib/Drupal/Component/Datetime/DateTimePlus.php</em>). <pre class="backtrace">Drupal\datetime\Plugin\views\filter\Date->opSimple('sesame_quota_option__field_sesame_opt_date.field_sesame_opt_date_value') (Line: 314)
Drupal\views\Plugin\views\filter\NumericFilter->query() (Line: 1370)
Drupal\views\ViewExecutable->_build('filter') (Line: 1259)
Drupal\views\ViewExecutable->build() (Line: 390)
Drupal\views\Plugin\views\display\PathPluginBase->execute() (Line: 180)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1627)
Drupal\views\ViewExecutable->executeDisplay('page_1', Array) (Line: 77)
Drupal\views\Element\View::preRenderViewElement(Array)
call_user_func(Array, Array) (Line: 378)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 76)
Drupal\webprofiler\EventDispatcher\TraceableEventDispatcher->dispatch('kernel.view', Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 38)
Drupal\webprofiler\StackMiddleware\WebprofilerMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 664)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Comments
Comment #2
goz commentedComment #3
goz commentedComment #5
goz commentedFix missing use declaration
Comment #6
goz commentedAdd some tests to not check grouped filter and empty value.
Comment #7
manicato commentedAfter applying the patch the date filter only accepts MM/DD/YYYY date format. My default date format is DD/MM/YYYY. When I select 13/05/2018 I get a "Wrong date format" error.
Comment #8
mpdonadioSeems like proper fix. Not sure about the format thing. Hmmm.
Comment #9
mpdonadioI wonder if we can really do anything about the format until #2648950: [PP-2] Use form element of type date instead textfield when selecting a date in an exposed filter lands. Date::opSimple() and ::opBetween() basically do the same thing. Since a format isn't chosen, you are at the whim of what DTP will do (the Rethans book probably has the best explanation).
Wondering out loud if we want to add the timezone here (and below) to mirror what the filter does?
Comment #10
dhirendragrazitti commentedI am also facing the issue in on of the website. How to resolve this.
The website encountered an unexpected error. Please try again later.Exception: DateTime object not set. in Drupal\Component\Datetime\DateTimePlus->__call() (line 355 of core/lib/Drupal/Component/Datetime/DateTimePlus.php)
Any help would be appreciated. when I upgraded the site from drupal 8.3.9 to drupal 8.5.3.
Comment #11
pixelpreview@gmail.com commentedSame problem with date between in my french website
Comment #12
stsier commentedThe patch #6 is almost good. It lacks this workaround into validateExposed()
$dt might be false when using relative dates like "+1 month "
Comment #13
pixelpreview@gmail.com commentedyes something like this :
a code like this works in local with exposed dates filter
the difficulty is to extend to a global solution for all Europeans languages like fr, nl, de for example and formats for other countries like YMD
https://en.wikipedia.org/wiki/Date_format_by_country
Comment #15
Sudheesh S. Babu commentedI have a view which can be filtered by using a date exposed filter. The filtering didn't work properly. The patch https://www.drupal.org/project/drupal/issues/2966735#comment-12590809 works for me. But I had to alter it a little bit to remove the timezone data from the dates, which was causing the bug in my case.
My altered custom patch is attached to this comment. I think it's not the proper way of adding extra functions to the core file.
Comment #16
madmax69 commentedhello
i have the same problem
Exception: DateTime object not set. in Drupal\Component\Datetime\DateTimePlus
I have test the patch 6 and i have a blank page
any news please ?
i have error : Avalid date format,
i have put the last patch and i have theses errors :
core/modules/datetime/src/Plugin/views/filter/Date.php).
Drupal\datetime\Plugin\views\filter\Date->validateExposed(Array, Object) (Line: 140)
Drupal\views\Form\ViewsExposedForm->validateForm(Array, Object)
call_user_func_array(Array, Array) (Line: 82)
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 275)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'views_exposed_form') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('views_exposed_form', Array, Object) (Line: 576)
Drupal\Core\Form\FormBuilder->processForm('views_exposed_form', Array, Object) (Line: 319)
Drupal\Core\Form\FormBuilder->buildForm('views_exposed_form', Object) (Line: 135)
Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase->renderExposedForm() (Line: 1238)
Drupal\views\ViewExecutable->build(NULL) (Line: 1391)
Drupal\views\ViewExecutable->execute(NULL) (Line: 1454)
Drupal\views\ViewExecutable->render() (Line: 131)
Drupal\views\Plugin\views\display\Block->execute() (Line: 1630)
Drupal\views\ViewExecutable->executeDisplay('listing', Array) (Line: 77)
Drupal\views\Element\View::preRenderViewElement(Array) (Line: 59)
Drupal\views\Plugin\Block\ViewsBlock->build() (Line: 163)
Drupal\block\BlockViewBuilder::preRender(Array)
thank you very much
Comment #17
pq commentedPatch from #15 rerolled for D8.7.x
Comment #18
mpdonadioNity, should be alphabetical.
Prob should be protected. Also needs $date_data and return documented in the docblock.
Need to look at this closer but we need a test to demonstrate the problem in the IS, and then show that this fixes it. So, back to Needs Work.
Comment #19
omnia.ibrahim commentedI applied patch #17 and got the error:
( ! ) Fatal error: Cannot use Drupal\Core\Form\FormStateInterface as FormStateInterface because the name is already in use in /var/www/html/docroot/core/modules/datetime/src/Plugin/views/filter/Date.php on line 15
Comment #20
handkerchief#17 works for me.
Drupal 8.7.5
Comment #22
jurgenhaasThe patch from #17 is working despite the fact that it introduces a couple of new minor issues. At least the major problem is gone.
Comment #23
ravi.shankar commentedHere I have added a new patch after making changes as suggested in comment #18.
I have also removed the commented code from patch #17.
But it still needs tests.
Comment #24
hdotnet commentedI'm experiencing this issue too, often triggered by crawlers.
category=22&field_publication_date_value[max]=nowfield_publication_date_value[min]=1990-01-01&items_per_page=50&language=***LANGUAGE_language_interface***&market=All&page=4&vt=4
Looking at the query I think my issue is more around a missing & in the GET string.
Not sure that the error deserves a WSOD of death though.
#17 works for me, Drupal 8.8.5
Comment #26
psf_ commented#23 don't works for me, I have problems with date formats. It only allows English format.
And if I set "greater than or equal to" filter I get:
Comment #27
danielvezaI'm running into this too, on a multilingual site. Investigating now.
Comment #30
andrei.vesterliHello there
I've just done a re-make for the patch for core 9.3.9. Hopefully, this will work ok.
Regards,
Andrei
Comment #31
andrei.vesterliWho can review the latest patch and say something in terms of coverage?
Comment #33
odai atiehI rerolled #23 patch and added some changes.
Comment #36
cilefen commented@Odai Atieh Would you please post an interdiff illustrating those changes, and perhaps describe what they are?
Comment #37
cilefen commentedThis is a reroll of #30 for 9.4.x.
#33 may be interesting, but it isn't explained and it failed tests. I'd like to hear more about it.
Comment #39
piggito commentedI noticed the last patch was only working for the case when we expose the operator so I updated MR https://git.drupalcode.org/project/drupal/-/merge_requests/2151 to also consider the cases when operator is not exposed and when using operator IS BETWEEN
Comment #40
Manibharathi E R commentedAfter Updating the Patch #37 is failing. Issue still not fixed in Drupal 9.4.x.
Steps to reproduce:
1. Create a date field in the Entity bundle.
2. Create a view with Date exposed filter.
3. Search any keyword and Date format will get the Error message in the Recents.
Comment #41
gaele commentedLatest MR as patch attached.
Comment #42
jaime@gingerrobot.com commentedComment #44
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #45
arunkumarkI also faced the same issue with the Date time object on the Views exposed filter having the wrong Date format. The issue is due to the Views Token filter module. After the proper token update it works fine.
But, expected to show a valid error or warning rather than a page break. The patch was not applied with the latest version of Drupal core 10.1.x. Rerolled the patch and resolved the page break.
Comment #46
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #47
akram khanadded updated patch fixed CCF #45. modifies the validateExposed() function to use a local variable $form_element to hold the field element that needs to be set with the form error message. It also changes the if-else block to use the null coalesce operator instead of an if-else block for brevity.
Comment #48
akram khanComment #49
smustgrave commentedAlso look at the tags please. Was previously tagged for test which are still needed.
Comment #50
edwardsay commentedPatch works, but not in case the form element in the exposed form is placed inside a container or other wrapper. I added support for this case. Also, I faced an issue with the "reset" button while testing this patch: validation didn't let me perform the reset action. So I added improvement for that case as well.
Comment #51
edwardsay commentedCode style improvement.
Comment #54
douggreen commentedI still get a PHP warning in AttributeArray (line 79) because the original input array is statically cached in ViewExecutable::getExposedInput() on line 726, which happens before the data is validated. We need to validate the data before it is saved.- This may be a project specific error, please ignore for now.Comment #55
greg boggsSaw this exception in my log slowing down my website because bots trigger this one a lot. Looks like there's been significant work done on this merge request since it's last review.
Comment #56
smustgrave commentedSeems will still need test coverage for this. MR should be updated for 11.x
Comment #57
oily commentedComment #58
oily commentedComment #59
oily commentedI have reproduced the error in the UI of Drupal 11.x-dev. See screenshot of the test view
Comment #60
oily commentedSee the screenshot of the error message
Comment #61
aurora.luzzardiThe current solution seems not to solve the issue if a URL accessing the date field has an invalid date format.
For example, we received this request:
?to_date[date]=../admin/noop.cgi?foo=bar&test=blahA bot trying to brute force and causing issues, in that case, it throws the same error:
I will check to apply a fix for that case too.
Comment #64
oily commentedThe new validation function validating a view datetime field
Comment #65
oily commentedTest coverage is now in place. Changing status to 'Needs review'.
Comment #66
oily commentedComment #67
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #68
oily commentedApplied bot fix
Comment #69
oily commentedComment #70
oily commentedComment #71
smustgrave commentedWhy remove Needs Review Queue Initiative tag?
Comment #72
oily commentedGood spot. Have restored the attribute.
Comment #73
oily commentedComment #74
smustgrave commentedBelieve feedback has been addressed here.
Comment #75
quietone commentedI read the comments and the MR and tested the change locally. I find that all questions are answered. I also updated credit.
And, I'd like to remind committers that screenshots should be available from the issue summary.
Leaving at RTBC
Comment #78
catchCommitted/pushed to 11.x and cherry-picked to 10.5.x, thanks!
Comment #80
greg boggsoh heck yeah. Can't wait to upgrade. This is my only logged error.
Comment #82
bserem commented@greg FYI the patch from gitlab applies nicely to 10.4.8
Comment #83
lifesxff commentedTested the patch on Drupal 11.1.6, and it doesn’t apply.