Problem/Motivation
After upgrading my site from Drupal 8.9.20 to 9.3.2, I found that various views I'd created were reporting relationships as "broken/missing handler". These broken relationships all involved
Paragraph →
entities, which make use of
Entity Reference Revisions →
.
Several other people have reported a similar problem following a D8 to D9 upgrade. See
here
🐛
Views Term ID has broken filters ("All of", "Is none of") and contextual filters "allow multiple"
Needs work
and here and
here →
.
Steps to reproduce
I haven't tried to reproduce this problem from scratch.
Proposed resolution
Others who have come across this problem have said that the solution is to simply delete the broken relationship, and recreate it. Whilst this solution is effective, it is rather tedious and error prone, especially if you have lots of views, or your views have lots of fields which use the broken relationship - all will need to be created again. Instead, I looked for a better way.
Having deleted the broken relationship and re-created it in one of my views, I examined the exported config file to see what had actually changed. I found that the difference was trivial. In the original (broken) config file, the relationship referred to "field_XXXXX_target_id" or "field_XXXXX_target_revision_id", whereas in the fixed config file, the relationship is simply "field_XXXXX". (There was also a difference to the admin_label for the relationship, but that's purely cosmetic.)
So, it seems that in D9, views (in some circumstances) store relationships differently to the way they were stored in D8. I would have expected an update hook to modify the definition for D8 views to make them D9 compatible. Writing such a hook is beyond me, but I've found that views can be updated by applying some simple text edits to their config files. Here are the steps that worked for me.
- Find the details of the broken relationships: Go to the view edit page, open the Advanced section, and look under Relationships to see where it says "Broken/Missing handler". Click on that link and you'll get details of the relationship. Take a note of the id - it will be something like "field_XXXXX_target_id" (or possibly "field_XXXXX_target_revision_id")
- If your view has multiple broken relationships, get the id for each one. (Ignore any bits about "broken/missing handlers" on fields or filters or otherwise - these are all just implications of the broken relationship.)
- Edit the view config file: Use your favourite text editor to open the config file for the view, and do a search/replace for the broken relationships. Search for " field_XXXXX_target_id", and replace with " field_XXXXX". (Note: include a space in front of the id to avoid picking up partial string matches relating to something else.)
- Re-import the revised view definitions: drush cim.
I did find that one view was so badly broken that I wasnt able to open the view edit page for it (the site crashed with a white screen of death). In this case, I simply looked in the config file, found the "relationships" section, and from that got the ids of all the relationships. I made a guess at which were the broken ones, and edited the file as above. When I re-imported the definition, all was well.
Remaining tasks
It would be nice to have a database update hook that can make the necessary changes to the view definitions.
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
None