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.

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

Aporie created an issue. See original summary.

aporie’s picture

Status: Active » Needs review
jan kellermann’s picture

I 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".

aporie’s picture

Thanks @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.

  • Aporie committed 2ecec6fa on 1.0.x
    Remove wrongly pushed hotfixed #3396324
    
aasarava’s picture

Status: Needs review » Reviewed & tested by the community

Thanks 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.

  • aporie committed 05f6e6a2 on develop
    Issue #3396324: Undefined constant "Drupal\node\Entity\DRUPAL_OPTIONAL"
    

aporie’s picture

Status: Reviewed & tested by the community » Fixed

I think it's quite safe.

I've been using this fix for a while and it seems to work.

Will release soon.

Status: Fixed » Closed (fixed)

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