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
- Install the module
- Add a link field on the User entity type (or another entity type that has no bundles.)
- Enable "Scan for broken links" on the new field
- 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);
}
Comments
Comment #2
dozz commentedComment #3
enchufeRerolled patch #1 for branch
2.1.x.Comment #4
eiriksmThanks for your work here people ♥️🙏
Is there a core or contrib entity type to use to reproduce this?
This way it should be easy to add a test, which I think we need here
Comment #5
shivam_tiwari commentedI am working here.
Comment #7
shivam_tiwari commentedI got issue as mentioned here. Created MR 107. It is working for me. Adding screenshots of before and after applying changes. Moving this to Needs review state as pipeline is green.
Comment #8
eiriksmThere are still no clear steps to reproduce this issue, and still no tests 🤓✌️
Comment #9
eiriksmOh there are steps here now, awesome!
That should make it trivial to write a test then!
Comment #11
jwilson3I also hit this issue and confirmed the MR as-is (without tests) does in fact fix the bug.
I took a stab at adding a test using the core User entity, since it is the most obvious choice of a bundleless entity type and matches the reproduction steps in the issue summary.
The test itself is tightly scoped to just a Link field to the User entity, create a user, and assert that LinkExtractorBatch::getTotalEntitiesToProcess() no longer throws the SQL error and correctly returns 1.
I ran tests locally and confirmed without the codefix the fatal error is triggered. I then ran the test again with the code fix and the test passes.
without fix:
However, both locally, and now on the CI pipeline, I see 10+ unrelated test failures when running all tests (as opposed to just the single new test I initially ran).
This MR branch is somewhat behind the latest 2.1.x branch, so I decided to see what would happen merging latest 2.1.x into my working copy of the MR branch and sadly, I still see the same failures. These failures are fundamentally unrelated to this issue, and they would affect ANY MR in the issue queue, and therefore this needs a follow-up issue.
I can safely remove the "Needs tests" tag now, and putting into NR, in case a maintainer might want to merge in spite of the unrelated test failures.
Comment #12
jwilson3I fixed the unrelated CI failures in a separate issue, that I hope can get reviewed and merged so we can see tests working here too. Thanks!
#3582328: Fix broken tests blocking CI pipeline success