Problem/Motivation
Getting the follow error while working on a new test in #2614720: Fatal errors while loading/building orphaned comments
1) Drupal\Tests\comment\Functional\CommentOrphanedTest::testNoOwner
TypeError: Argument 1 passed to Drupal\Core\Entity\EntityViewBuilder::resetCache() must be of the type array or null, object given, called in /opt/sites/d8/core/tests/Drupal/Tests/EntityViewTrait.php on line 64
Line 64 is the resetCache in this block:
if ($reset) {
$render_controller->resetCache([$entity->id()]);
}
which is passing an array of strings to resetCache
which expects the first parameter to be an array of entities.
The failure will happen when buildEntityView(EntityInterface $entity, $view_mode = 'full', $langcode = NULL, $reset = FALSE
) is called with reset set to TRUE. There are currently no instances of that in core but the new test in #2614720: Fatal errors while loading/building orphaned comments does set reset to TRUE.
Steps to reproduce
Proposed resolution
Change \Drupal\Tests\EntityViewTrait::buildEntityView from
if ($reset) {
$render_controller->resetCache([$entity->id()]);
}
to
if ($reset) {
$render_controller->resetCache([$entity]);
}
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#13 | 3163924-13.patch | 1.4 KB | quietone |
#11 | 3163924-11.patch | 2.66 KB | quietone |
#11 | interdiff-8-11.txt | 2.29 KB | quietone |
#8 | 3163924-8.patch | 1.74 KB | quietone |
#8 | 3163924-8-fail.patch | 1.07 KB | quietone |
Comments
Comment #2
quietone CreditAttribution: quietone as a volunteer commentedComment #3
quietone CreditAttribution: quietone as a volunteer commentedA simple patch. I'd write a test for this but don't know where to start.
Comment #4
larowlanI think a kernel test that loads an entity using this trait, and renders it with the reset flag set should be enough for testing sake
Comment #5
quietone CreditAttribution: quietone as a volunteer commentedThx, I woke up the next day with the same thought.
Comment #8
quietone CreditAttribution: quietone as a volunteer commentedWrong namespace.
Comment #10
BerdirTo be honest, seems pretty overkill to even offer this option. Clearly this wasn't ever used before and probably just added to have parity with other somewhat similar methods like \Drupal\Tests\node\Traits\NodeCreationTrait::getNodeByTitle() but the use case here is very different. That other one is mostly about the static cache and mismatch between web requests and the test runner and #3040878: Reset static entity cache on POST requests in tests would cleanly remove the need for that.
The render cache however is 99% transparent. saving the entity invalidates that, even across the web requests/test runner. The only case when you need this is when you do shady things like manually alter database tables. And it's not enough, you need to reset the storage cache as well.
I know it's kinda out of scope, but I do wonder if we shouldn't just deprecate this argument and remove it in D10. Trigger a deprecation mesage if you pass in TRUE.
Comment #11
quietone CreditAttribution: quietone as a volunteer commentedThanks. It does seem odd to fix this when it isn't used anywhere. I support deprecation.
I am not sure if this needs to be done in two issues or if it can all be done here. In any case, I started a patch with the deprecation. There isn't a change record yet.
So fix this and then a new issue or all in one?
Comment #12
larowlanAll in one sounds good to me
Comment #13
quietone CreditAttribution: quietone as a volunteer commentedFrom Slack discussion
So, new patch that removes the fourth parameter etc.
Participants:
larowlan, Berdir, quietone
edit: fix table formatting
Comment #14
BerdirYeah, lets do this :)
Feels like entity system would be a better component even though the code is technically in the generic test traits namespace, but doesn't matter too much.
Comment #16
BerdirJust that ckeditor random fail.
Comment #17
larowlanCommitted fecfd28 and pushed to 9.1.x. Thanks!
Thanks folks