Problem/Motivation
The linkchecker module is throwing a fatal PHP error when attempting to save links during the link extraction process. The error occurs in the LinkExtractorService::saveLink() method at line 376, where the code attempts to call getEntityTypeId() on a null object.
Error: Call to a member function getEntityTypeId() on null in Drupal\linkchecker\LinkExtractorService->saveLink() (line 376 of /var/lib/tugboat/web/modules/contrib/linkchecker/src/LinkExtractorService.php)
This error prevents the link checking functionality from working properly and can cause site crashes or incomplete link extraction processes.
Steps to reproduce
- Enable the linkchecker module
- Configure link checking for content entities
- Create or update content that contains links
- Trigger the link extraction process (either manually or via cron)
- Observe the fatal error in logs
Proposed resolution
The error suggests that an entity object is expected but null is being passed instead. The fix should include:
- Validate entity states: Ensure entities are properly loaded and accessible before processing
- Add null checks: Verify that the entity object exists before calling methods on it
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 3543895-linkchecker-null-parent-entity-fix-6.patch | 532 bytes | enchufe |
| #2 | 3543895-linkchecker-null-parent-entity-fix.patch | 682 bytes | davidburns |
Comments
Comment #2
davidburnsComment #3
eiriksmThanks for the patch, that looks very correct. 👌🌈
However, the steps to reproduce seem inaccurate? And the suggested fix does not align with what is the proposed solution? Based on the content of the text it seems to be generated by some LLM, so not surprised about this inaccuracy 🤓
For sure we have tests that covers exactly the steps to reproduce. So I feel pretty confident that is not the case. Which makes also the patch and issue hard to QA and verify.
In addition. Once we have actual accurate steps to reproduce it should be easy to add a test for this as well.
So the status is "needs work" based on
- needs steps to reproduce
- needs test
- needs issue summary update
Thanks for the contribution! 🚀
Comment #4
davidburnsHi @eiriksm,
You are correct that I used AI to generate the ticket description.
The only piece that was really missing from the description was that linkchecker was working fine up until I ran the committed codebase through PHPCS and PHPSTAN then fixed a massive amount of coding standards in custom themes and modules. I committed the code to the git provider where all our checks and tests run. The test that failed was when it ran cron on our Tugboat environment. I was able to confirm this error when I ran cron locally with the latest database. The site that the test ran on did have A LOT of broken links across many different entity types and I didn't capture exactly where it failed.
After creating and applying this patch all tests and checks passed.
Comment #5
davidburnsComment #6
enchufeVersion
2.1.0solves the issue, but I've reworked the patch #2 to improve the code and prevent other related errors.Comment #7
enchufe