Database exception: Unknown column 'base.' when using entity types without bundle

Created on 23 June 2023, over 1 year ago

Problem/Motivation

I get the following fatal error message when trying to check links on entities that have no bundle.
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'base.' in 'where clause'.

Entities without a bundle are considered as having exactly one bundle. The bundle is the same the entity type id but they don't have a bundle key so the following lines result in the exception.

      if (!empty($bundle)) {
        $query->condition('base.' . $entityType->getKey('bundle'), $bundle);
      }

Steps to reproduce

  1. Install the module
  2. Add a link field on the User entity type (or another entity type that has no bundles.)
  3. Enable "Scan for broken links" on the new field
  4. Visit the configuration page of the Linkchecker module

Proposed resolution

Also check that the bundle key is not empty.

      if (!empty($bundle) && $entityType->getKey('bundle')) {
        $query->condition('base.' . $entityType->getKey('bundle'), $bundle);
      }
🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

🇧🇪Belgium Dozz

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

Comments & Activities

Production build 0.71.5 2024