After update from 8.x-4.0-beta2 for anonymous (there is rules bith blocks)
The website encountered an unexpected error. Please try again later.
Error: Call to a member function getCacheTags() on null in Drupal\context\Plugin\ContextReaction\Blocks->execute() (line 252 of modules/~context/context/src/Plugin/ContextReaction/Blocks.php).
D:8.9.6 PHP:7.2
| Comment | File | Size | Author |
|---|---|---|---|
| #32 | context-3173470-17.patch | 2.98 KB | sgalata |
| #16 | context-3173470-16.patch | 2.93 KB | mingsong |
| #15 | context-3173470-15.patch | 2.46 KB | mingsong |
| #13 | context-3173470-13.patch | 2.5 KB | mingsong |
Issue fork context-3173470
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
promo-il commentedComment #3
elgandoz commentedSame issue here, from 8.x-4.0-beta2 to 8.x-4.0-beta5.
Comment #4
robin.ingelbrecht commentedCan confirm this issue, from 8.x-4.0-beta4 to 8.x-4.0-beta5.
Comment #5
robin.ingelbrecht commentedOk, I had a context where a block was referring to a non existing context_id. I edited the config yml file imported it again and the problem was fixed.
Comment #6
deaom commentedHi @all, could somebody with the issue, if still present, post steps do reproduce the issue?
Comment #7
paulocsHello @all,
Did you run the update.php when upgrade it to the 8.x-4.0-beta5 version?
@Promo-IL and @elgandoz, can you see if the config yml from your context are referring to a non existing context_id like @robin.ingelbrecht said?
Comment #8
maxmendez commentedI got the same problem with one of my context, reviewing the conf file of the context the problem is in the context_id key, in my case the value was saved translated.
I've catched the error editing the context saving the block and reviewing the conf diff.
Comment #9
promo-il commentedre paulocs #7 Yes update the update was started, and applied to the base
Comment #10
promo-il commentedre: paulocs
Right. It is necessary in any case to recreate Reactions of rules with block (if error).
Comment #11
promo-il commentedComment #12
mingsongI believe this issue is related to #3122023: Notice: Undefined Index Errors All Over
Comment #13
mingsongWe came across this issue too which brings the entire site down.
Here is a patch for a quick fix.
Todo:
A update hook to update all reactions in which the context id is missing.
Comment #14
klonosReopening this issue to draw the attention of the maintainers. This has broken multiple sites hosted on the GovCMS platform. Please review the provided patch.
Comment #15
mingsongThe patch #13 is for 8.x-4.0-beta5 which doesn't fit in 8.x-4.x-dev.
Here is the patch for 8.x-4.x branch for now.
Comment #16
mingsongPatch for 8.x-4.0-beta5 with fixing to avoid PHP notice messages.
Comment #17
sonfdI ran into this when I changed the machine_id of a context after it was created and configured. In my case the context_id for the block reactions in the context configuration yaml file were still pointing to the old context machine id. Updating this to the new context id and re-importing resolved the issue.
Comment #19
deaom commentedContext_id is always required, so I do not see a need to check if is set, as it needs to be set. Following the steps that @sonfd provided, I could reproduce the issue on the edit context page itself. So if I have a context named test and I add a reaction block to it everything works, then I go back and I edit the machine name (with the click on the edit), then I get the above described error for the getCacheTags(). But that is because the test context entity no longer exists, but debugging it I still get the context_id, just not the correct/new one, but the old one.
I added additional check for the tags in $block_build to get cache tags only if context_entity is not null/empty, otherwise set empty array. Then the update of the new machine name goes through, with the "error page" of test context page not existing on the structure/context/test url/page, but with the message that test-new context was saved/created. If I then visit the structure/context/test-new, everything is working normally, with no errors.
But the issue here is, as also @sonfd describes, that the blocks reaction is still pointing to the old context_id, which means the $context_entity is still going to be null/empty, even tough for some strange reason the reactions are displaying correctly. If you then go to the block click on edit and update the block, it updates to the correct context_id for the block reactions.
So the question here is, should the module/code handle that update after a machine name change (without additional updating of the blocks by user), or if that falls on the user end?
Comment #20
magdalenaa67 commented#16 - context-3173470-16.patch worked for me. Added the patch to my composer.json. Composer install etc.
I had the exact same error as listed above. It only effected one content type, event.
Comment #21
nmatja commentedUpdate #16 worked for me as well.
Comment #22
adalbertov commentedI tested #18 and it looks good.
Comment #23
paulocsI agree with @DeaOm. And in my opinion we should update the block context_id when the context machine name is changed.
I pushed a commit so it can be done.
I also think we can keep the verification in line 255 from
Drupal\context\Plugin\ContextReaction\Blocks.phpso it will prevent the errors.Comment #24
balis_m commentedLatest changes (Merge request !7) worked for me.
Comment #25
deaom commentedThe added hook_ENTITY_TYPE_presave() updates the block_id after a machine name change, which can also be seen with the exporting of the configuration, so marking this as RTBC.
Comment #26
paulocsSmall change so
$context->save();is not called unnecessarily.Comment #27
paulocsI revert the commit because it doesn't work.
Comment #29
paulocsI merged it into the last dev version.
Thanks!
Comment #31
mingsongPatch #16 also fixes an undefined index error, which is reported by
https://www.drupal.org/project/context/issues/3204399#comment-14074606
It seems that that issue still remains.
Is it considered?
Comment #32
sgalata commentedIt seems is still an issue so I have created another patch that can be applied to the latest context version (8.x-4.1 as of the writing of this comment)