A very similar problem like #2807567: Checkout fails when Editor module enabled. arises to me after updating from pre-beta version to beta2.
TypeError: Argument 1 passed to _editor_get_file_uuids_by_field() must implement interface Drupal\Core\Entity\EntityInterface, null given, called in /var/www/drupalvm/web/core/modules/editor/editor.module on line 381 in _editor_get_file_uuids_by_field() (line 479 of core/modules/editor/editor.module).
Steps to reproduce:
- Editor module is turned on
- Make sure, no active cart exists
- Add a product to the cart
This leads to nested save and load calls of the order entity, leading to stale data during the order refresh process. Shortly explained, these save calls happen:
- The cart provider is creating a new order entity and saving it.
- The entity itself is setting the order number to its id in postSave()
- The storage loads the entity in its pre save hook
- OrderRefresh process is started on load, saving the order entity again
- Somewhere must be the place, where the data gets stale. the entity is missing its id and order number now, at least also the "original" property added on presave in the storage, gets lost. that's why later on the editor's entity update hook fails
- That's also why you the postSave() function of the order entity again tries to set the order number again and does an additional save call
Really strange thing here.. Maybe the OrderRefresh is working on the unchanged entity too?? I haven't found out until now. The only thing I know, is that getting rid of a single save() call makes the problem go away. That also solved the related issue, but still means that it could happen at any time on any place again. E.g. you could repeat the setting of the order number in a preSave() hook again, which seems to prevent one save() action on stale data later.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 2820034-prevent_order_refresh_on_unchanged_loads-7.patch | 2.93 KB | agoradesign |
Comments
Comment #2
agoradesign commentedThe following PR adds editor module as a test dependency in order to let AddToCartFormTest fail:
https://github.com/drupalcommerce/commerce/pull/536
Comment #3
agoradesign commentedupdated the PR - after discussion with mglaman decided to use a custom hook_entity_update() implementation in the test module instead of depending on editor
Comment #4
agoradesign commentedThe more I think about that, I'm suspect more and more one thing, I've already mentioned in the issue summary:
I guess OrderRefresh is acting also on loading the unchanged entity, which is added as $entity->original by the storage - because loadUnchanged() only resets the static cache and then does call normal load methods, including firing load events of course. However OrderRefresh should never ever act on that. Maybe the order storage needs to override loadUnchanged() and set a flag or so... This smells like a workaround too, but at least it would/could work atm. Further discussion would have to been taken with Core maintainers.
PS: don't have the possibility right now to proof that, neither do I see the backtrace, but I'm very convinced that this could be the cause!
Comment #5
agoradesign commentedSeems that my theory was right. See the PR and/or the attached patch. I've added a check to order storage's postLoad hook, in order to prevent that the order refresh process is called on unchanged loads ($entity->original).
attention: only verified it so far on my added test, which failed before and now passes. Did no tests in a real environment,...
Comment #6
agoradesign commentednext try...
Comment #7
agoradesign commentedtiny change to the test module... now it should be ok
Comment #8
bojanz commentedI've commented on the PR, we're almost there.
Comment #9
bojanz commentedDiscussing this further we realized that the order frequency protects against this, agoradesign was still seeing the problem because his site didn't have order frequency set (due to the update from alpha). The problem is visible in tests because orders stay loaded for longer than 30s (default frequency), an order is loaded, then saved a whole minute later, which causes the orderRefresh in loadUnchanged() to trigger.
Degrading priority to Major since not every install is affected.
Wrapping up the commit.
Comment #11
bojanz commentedBoom!