Problem/Motivation
When updating an entity programmatically (for example when trying to change an entity storage class with devel_php) then the entire website runs under a 500 error: Undefined constant "Drupal\node\Entity\DRUPAL_OPTIONAL"
This also happen when running tests.
From investigation in #3304657:
The issue is that whatever we do, during bootstrap phase, Drupal loads all module files in core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php::handle(). This middleware has a priority of 100 to "Prepares the environment after page caching ran". Until we try to run a query on a middleware with a higher priority (in my case 210, just before page cache middleware), there is no way to have the const DRUPAL_OPTIONAL defined.
Issue fork alert_message-3396324
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 #3
aporieComment #4
jan kellermann commentedI tested the patch and it resolved the problem. Thank you for your work!
(I can reproduce with editing the content type "basic page". After saving the form i get a WPOD.)
It was only a quick check and I could not test the whole system so I do not set the status to "Reviewed".
Comment #5
aporieThanks @jan for the feedback.
The same. I've deployed this patch to a project on production, it works well (but has some other issues similar to this one with classes not defined, whereas they are) only once, and I have no idea what triggered it.
Though this project has no cache and page_cache has been uninstalled, so the same, I can't really set this patch to "reviewed".
Let's wait for a while and we'll see.
Comment #7
aasarava commentedThanks for the patch. I reviewed and tested and can confirm it works.
Prior to the patch, I was able to reproduce the error by creating a webform and then deleting it. Upon deletion, I got the DRUPAL_OPTIONAL error and WSOD. Flushing cache was the only way to fix. After applying the patch, I can create and delete webforms without the error.
Comment #10
aporieI think it's quite safe.
I've been using this fix for a while and it seems to work.
Will release soon.