Loading entities can fail in Sql::loadEntities() for required entities, skip those rows

Created on 30 January 2019, over 6 years ago
Updated 25 April 2024, about 1 year ago

Problem/Motivation

This has been split off from 🐛 \Drupal\views\Plugin\views\query\Sql::getCacheTags and getCacheMaxAge don't take into account that some entities can be NULL Needs work , which results in the same error, but the situation and proposed fix is different.

Entities that failed to load result in this error:

Error: Call to a member function getCacheTags() on null in Drupal\views\Plugin\views\query\Sql->getCacheTags() (line 1552 of core/modules/views/src/Plugin/views/query/Sql.php).

I did load testing for a site we are working on and we've actually seen two cases in our project how this can happen:

a) Persistent inconsistent data. In our case, this happened because an already deleted entity was re-saved again ( #3029355: Deleting a node deletes the linked group_content entities which then resaves the node ), then the query built by views does find the node but an entity load on it fails. I'll open a separate issue to prevent this specific case from happening, but there might be other issues that could lead to this.

b) A race condition. In my case, I was doing a load test where 20 users each created, updated and then deleted a new and finally went to the content overview page. I did that 5x in a loop and had two errors like this on the content overview page. So what I think happened is that the node was deleted *between* executing the view and loading the nodes.

Proposed resolution

At least for the second case, I think we should just drop records where we can't load the main entity completely. Even if we avoid errors on the Sql class, various field plugins for example fail with a similar error, e.g. BulkForm and EntityOperations. That could mean we are hiding problems in a), but we could combine it with a warning log message, if something happens once then it was just a race condition, if it happens on every request then you have to fix the data.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Views 

Last updated 1 day ago

Created by

🇨🇭Switzerland berdir Switzerland

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024