Problem/Motivation
Discovered by @jeqq while testing the core Workspace module.
Steps to reproduce:
- enable the workspace module
- switch to a non-default workspace
- add an article node and try to upload an image (or remove the image from an existing article)
The problem lies within \Drupal\workspaces\EntityOperations and \Drupal\workspaces\FormOperations which are adding an entity builder and a form validate callback to all entity forms, without taking care of managing their own injected dependencies.
Proposed resolution
One solution would be to use DependencySerializationTrait in both those objects, but that's just a workaround and the usage of that trait should not be actively encouraged.
Instead, they should add their form callbacks as static methods, which ensures that the objects themselves are not being serialized when the form is being serialized in the db cache.
Remaining tasks
Review.
User interface changes
Nope.
API changes
Nope.
Data model changes
Nope.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 2998565-8.patch | 5.15 KB | amateescu |
| #8 | 2998565-8-test-only.patch | 2.07 KB | amateescu |
| #8 | poc-interdiff.txt | 1.17 KB | amateescu |
| #7 | poc.txt | 2.1 KB | sam152 |
| #2 | 2998565.patch | 6.68 KB | amateescu |
Comments
Comment #2
amateescu commentedThis should do it.
Comment #4
amateescu commentedComment #6
sam152 commentedI wonder if we could test these kinds of issues in the future by building the form and attempting to serialize/unserialize it in a kernel test. JS tests are a bit of a headache.
Patch looks good to me.
Comment #7
sam152 commentedHere is a POC for #6. I'll leave it out of a patch and keep RTBC for #2 if a full blown functional test is preferred here.
Comment #8
amateescu commentedWhoa, I love the much simpler way of testing this bug from #7!
The term "cacheable" has a very loaded meaning in D8, usually referring to the render cache. So I changed these descriptions a bit to mention that we're testing the form cache :)
Comment #10
sam152 commentedChanges look good to me. +1 RTBC.
Comment #12
sam152 commentedInfra hiccup.
Comment #13
alexpottNice test :)
Committed and pushed 9ff7e11bd7 to 8.7.x and 77584d1c3a to 8.6.x. Thanks!