Problem/Motivation
Error: Call to a member function setTime() on null in Drupal\Component\Datetime\DateTimePlus->setDefaultDateTime() (line 719 of /app/web/core/lib/Drupal/Component/Datetime/DateTimePlus.php)
#0 /app/web/modules/contrib/search_api/src/Plugin/search_api/data_type/DateDataType.php(36): Drupal\Component\Datetime\DateTimePlus->setDefaultDateTime()
#1 /app/web/modules/contrib/search_api/src/Item/Field.php(518): Drupal\search_api\Plugin\search_api\data_type\DateDataType->getValue('en')
#2 /app/web/modules/contrib/search_api/src/Utility/FieldsHelper.php(179): Drupal\search_api\Item\Field->addValue('en')
#3 /app/web/modules/contrib/search_api/src/Utility/FieldsHelper.php(144): Drupal\search_api\Utility\FieldsHelper->extractField(Object(Drupal\Core\Field\FieldItemList), Object(Drupal\search_api\Item\Field))
#4 /app/web/modules/contrib/search_api/src/Item/Item.php(266): Drupal\search_api\Utility\FieldsHelper->extractFields(Object(Drupal\Core\Entity\Plugin\DataType\EntityAdapter), Array, 'en')
#5 /app/web/modules/contrib/search_api/src/Plugin/search_api/processor/ContentAccess.php(172): Drupal\search_api\Item\Item->getFields()
#6 /app/web/modules/contrib/search_api/src/Item/Item.php(272): Drupal\search_api\Plugin\search_api\processor\ContentAccess->addFieldValues(Object(Drupal\search_api\Item\Item))
#7 /app/web/modules/contrib/search_api/src/Entity/Index.php(975): Drupal\search_api\Item\Item->getFields()
#8 /app/web/modules/contrib/search_api/src/Entity/Index.php(930): Drupal\search_api\Entity\Index->indexSpecificItems(Array)
#9 /app/web/modules/contrib/search_api/src/IndexBatchHelper.php(154): Drupal\search_api\Entity\Index->indexItems(50)
#10 /app/web/core/includes/batch.inc(295): Drupal\search_api\IndexBatchHelper::process(Object(Drupal\search_api\Entity\Index), 50, -1, Array)
#11 /app/web/core/includes/batch.inc(137): _batch_process()
#12 /app/web/core/includes/batch.inc(93): _batch_do()
#13 /app/web/core/modules/system/src/Controller/BatchController.php(55): _batch_page(Object(Symfony\Component\HttpFoundation\Request))
#14 [internal function]: Drupal\system\Controller\BatchController->batchPage(Object(Symfony\Component\HttpFoundation\Request))
#15 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#16 /app/web/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#17 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#18 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#19 /app/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#20 /app/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#21 /app/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 /app/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /app/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /app/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /app/web/modules/contrib/shield/src/ShieldMiddleware.php(115): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 /app/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\shield\ShieldMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 /app/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 /app/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 /app/web/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 /app/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#31 {main}
Steps to reproduce
I added a date field of type date to the index and the batch dies with the above errors.
I changed the type from date to string and I could index.
Proposed resolution
Remaining tasks
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3221345-4--invalid_date_field_values.patch | 2.81 KB | drunken monkey |
Comments
Comment #2
drunken monkeyThanks for reporting this issue!
At a glance, it seems obvious that we don’t properly guard against invalid date/time strings. Would be interesting to know what
$valueis for you in that code (in\Drupal\search_api\Plugin\search_api\data_type\DateDataType::getValue()), if you can find out – it migth still be problematic for you if the value then doesn’t get indexed properly.Anyways, the attached patch should add proper error checks (and logging). Please test/review!
Comment #3
jan kellermann commentedExamples from our customer's database are "1949-00-00" or "1942-07-00".
With this patch the indexing works for us.
ky.
Comment #4
drunken monkeyThanks a lot for the feedback, good to hear!
Not optimal that those won’t be getting indexed now, but still much better than stopping indexing completely (and probably can’t/shouldn’t be fixed in our module, if at all).
Just adding a test, too – if the test bot is happy with that, I’ll commit this.
Comment #6
drunken monkeyCommitted.
Thanks again!