Problem/Motivation

The Custom Elements views style plugin crashes with a TypeError when a view result row has a null entity ($row->_entity === null). This can happen when an entity is deleted between the view query execution and entity rendering, e.g. during concurrent requests or cache race conditions.

TypeError: Drupal\custom_elements\CustomElementGenerator::generate(): Argument #1 ($entity) must be of type Drupal\Core\Entity\ContentEntityInterface, null given, called in lupus_decoupled_views/src/Plugin/views/style/CustomElements.php on line 86

Steps to reproduce

1. Create a view using the Custom Elements style with an entity row plugin
2. Have content that gets deleted or becomes unavailable between query and render time (e.g. via concurrent requests, cron, or automated test cleanup)
3. The view crashes instead of gracefully skipping the missing entity

This is hard to reproduce manually but occurs in automated testing environments where multiple operations happen in quick succession.

Proposed resolution

Add a null guard for $row->_entity in CustomElements::render() before passing it to CustomElementGenerator::generate(). Rows with null entities should be silently skipped, consistent with how Drupal core handles missing entities in views rendering.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#3 3574300.patch867 bytespetar_basic
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

petar_basic created an issue. See original summary.

petar_basic’s picture

Assigned: petar_basic » Unassigned
Status: Needs work » Needs review
StatusFileSize
new867 bytes

Added a check to skip rows where $row->_entity is null in CustomElements::render(). When an entity can't be loaded (e.g. deleted between query and render), the row is now silently skipped instead of crashing with a TypeError. MR is up, patch attached (for use with composer patches).

fago made their first commit to this issue’s fork.

fago’s picture

Status: Needs review » Fixed

thx, straight-forward fix. Merged.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • fago committed 9fe145b0 on 1.x authored by petar_basic
    fix: #3574300 Views: TypeError when $row->_entity is null in...

Status: Fixed » Closed (fixed)

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