Error: Call to undefined method Drupal\feeds\State::messenger() in Drupal\feeds\State->displayMessages() (line 196 of modules/contrib/feeds/src/State.php).

Getting this error in watchdog logs and on feed page after updating core from 10.2.5 to 10.3.6 and feeds from 8.x-3.0-beta4 to 8.x-3.0-rc2 (along with some other modules).

Issue fork feeds-3487439

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

rudi teschner created an issue. See original summary.

rudi teschner’s picture

Issue summary: View changes
rudi teschner’s picture

Additional Stacktrace

Drupal\feeds\FeedViewBuilder->getBuildDefaults() (Line: 157)
Drupal\Core\Entity\EntityViewBuilder->viewMultiple() (Line: 123)
Drupal\Core\Entity\EntityViewBuilder->view() (Line: 134)
Drupal\Core\Entity\Controller\EntityViewController->view()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
Drupal\Core\DrupalKernel->handle() (Line: 19)
rudi teschner’s picture

Issue summary: View changes
megachriz’s picture

Thanks for reporting. I think that the error is related to incompleted imports at the time of the update.

Only weird thing is that it says "undefined method". I would have expected the error to be something like "cannot call addMessage() on null" or something similar.

megachriz’s picture

You don't have patches applied to Feeds, by any chance?

rudi teschner’s picture

Thanks for the fast reply. No, I don't have any patches for the feeds module applied.

I checked a different test system and there I actually get the error you mention (Error: Call to a member function addMessage() on null in Drupal\feeds\State->displayMessages()) during the cron runs. So it seems to actually be two different errors depending on whether the feed content page is accessed (i.e. /feed/8) or the cron jobs are executed.

What I wondered though ... the messenger is addressed different ways in the feed module. No clue if that has to do something at all though.

$this->messenger()

/src/Controller/CustomSourceListController.php:130:        $this->messenger()->addError($e->getMessage());
./src/FeedTypeForm.php:355:    $this->messenger()->addStatus($this->t('Your changes have been saved.'));
./src/Feeds/Processor/EntityProcessorBase.php:1292:          $this->messenger()->addWarning($this->t('When mapping to the entity ID (@name), it is recommended to set it as unique.', [
./src/FeedForm.php:225:      $this->messenger()->addMessage($this->t('%title has been created.', $t_args));
./src/FeedForm.php:229:      $this->messenger()->addMessage($this->t('%title has been updated.', $t_args));
./src/FeedForm.php:235:      $this->messenger()->addError($this->t('The feed could not be saved.'));
./src/Form/CustomSourceEditForm.php:137:    $this->messenger()->addStatus($this->t('The source %label has been updated on the feed type %feed_type.', [
./src/Form/MappingForm.php:161:          $this->messenger()->addWarning($this->t('Your changes will not be saved until you click the <em>Save</em> button at the bottom of the page.'));
./src/Form/MappingForm.php:392:      $this->messenger()->addWarning($e->getMessage());
./src/Form/MappingForm.php:1076:    !empty($message) ? $this->messenger()->addWarning(Markup::create(implode('<br />', $message))) : TRUE;
./src/Form/DeleteMultipleForm.php:53:      $this->messenger()->addMessage($this->formatPlural($count, 'Deleted 1 feed.', 'Deleted @count feeds.'));
./src/Form/FeedUnlockForm.php:45:    $this->messenger()->addMessage($this->t('%title has been unlocked.', $args));
./src/Form/FeedDeleteForm.php:73:    $this->messenger()->addMessage($this->t('%title has been deleted.', $args));
./src/Form/ClearMultipleForm.php:52:      $this->messenger()->addMessage($this->formatPlural($count, 'Deleted items of 1 feed.', 'Deleted items of @count feeds.'));
./src/Form/ImportMultipleForm.php:52:      $this->messenger()->addMessage($this->formatPlural($count, 'Imported 1 feed.', 'Imported @count feeds.'));
./src/Form/FeedScheduleImportForm.php:61:    $this->messenger()->addStatus($this->t('%title has been scheduled for import.', $args));
./src/Form/CustomSourceDeleteForm.php:100:    $this->messenger()->addStatus($this->t('The source %label has been deleted from the feed type %feed_type.', [
./src/FeedExpireHandler.php:26:      $this->messenger()->addWarning($this->t('The feed became locked before the expiring could begin.'));
./src/FeedExpireHandler.php:83:      $this->messenger()->addError($e->getMessage());
./src/FeedExpireHandler.php:105:      $this->messenger()->addStatus($this->t('Expired @count items.', ['@count' => $state->total]));
./src/Plugin/Type/Target/TargetBase.php:113:    return $this->messenger();
./modules/log/src/Form/DeleteForm.php:44:    $this->messenger()->addMessage($this->t('Log %id has been deleted.', [
./modules/log/src/Form/ClearLogConfirmForm.php:47:    $this->messenger()->addStatus($this->t('Logs cleared for feed %label.', [

against \Drupal::messenger()

./feeds.install:49:  $messenger = \Drupal::messenger();
./tests/src/Kernel/FeedsEventsTest.php:63:    $messages = \Drupal::messenger()->all();
./tests/src/Kernel/FeedsEventsTest.php:68:    \Drupal::messenger()->deleteAll();
./tests/src/Kernel/FeedsEventsTest.php:92:    $messages = \Drupal::messenger()->all();
./tests/src/Kernel/EntityIdTest.php:52:    $messages = \Drupal::messenger()->all();
./tests/src/Kernel/EntityIdTest.php:165:    $messages = \Drupal::messenger()->all();
./tests/src/Kernel/Feeds/Processor/GenericContentEntityProcessorTest.php:106:    $messages = \Drupal::messenger()->all();
./tests/src/Kernel/Feeds/Target/LinkTest.php:83:    $messages = \Drupal::messenger()->messagesByType('warning');
./tests/src/Kernel/Feeds/Target/TimestampTest.php:105:    $messages = \Drupal::messenger()->messagesByType('warning');
./tests/src/Kernel/Feeds/Target/BookTest.php:297:    $messages = \Drupal::messenger()->all();
./tests/src/Traits/FeedsCommonTrait.php:351:    $messages = \Drupal::messenger()->all();
ajetiv1’s picture

Same here, getting the following message:

Error: Call to a member function addMessage() on null in Drupal\feeds\State->displayMessages() (line 196 of modules/contrib/feeds/src/State.php).

megachriz’s picture

Status: Active » Needs review

I provided a possible fix in the MR. I did not test it yet though. I'm still working on the automated tests.

If you want to apply the code to Feeds 8.x-3.0-rc2, you also need to apply the code from #3479242: Error: Serialization of 'CurlHandle' is not allowed in serialize().

megachriz’s picture

The provided fix in the MR should be fixing this issue. 🙂

It would be great if you can test it, I plan to merge it this Thursday.

rudi teschner’s picture

I've added the changes in State.php to a system that had the messages appear every 5 minutes in watchdog - and the messages don't appear anymore

  • megachriz committed eb5147da on 8.x-3.x
    Issue #3487439 by megachriz, rudi teschner: Fixed call to a member...
megachriz’s picture

Status: Needs review » Fixed

@rudi teschner
Cool, thanks for testing. I merged the code!

rob230’s picture

That patch doesn't apply. I tried applying https://www.drupal.org/project/feeds/issues/3479242 first. Are there specific commits or merge requests that need to be applied in a certain order?

rob230’s picture

StatusFileSize
new2.22 KB

That is what I tried. I also tried applying every commit since October, and they all apply except for this ticket. There must be something weird about the diff with binary file added which means composer can't apply it.

I've created a patch containing just the 2 required commits and no tests for anyone who wants to fix the WSOD on 8.x-3.0-rc2.

It would be good to get a new release because currently anyone who updates gets a WSOD!

megachriz’s picture

@rob230
I wasn't aware that this issue caused a WSOD, I thought it generated only some errors on the feed page.

Thanks for creating the patch, I can see that applying the diff could be troublesome because of the binary file. I hadn't tried applying the diff with Composer, I only tried it like this:

curl https://git.drupalcode.org/project/feeds/-/merge_requests/199.diff | git apply
curl https://git.drupalcode.org/project/feeds/-/merge_requests/205.diff | git apply

I didn't think about that for Composer it could cause trouble.

While I think this issue doesn't affect everyone who updates Feeds (it only affects sites that have unfinished imports at the time of updating), good call on creating a new release. I can do that this Thursday.

megachriz’s picture

@rob230
A new release has been created!
https://www.drupal.org/project/feeds/releases/8.x-3.0-rc3

Status: Fixed » Closed (fixed)

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