Problem/Motivation
Relationships for users to the nodes they've created are defined by the User module. The Node module may be uninstalled, but the User module may not. So the User module provides view relationships that can be invalid.
Steps to reproduce
- Uninstall the Node module.
- Add a new view for User entities.
- Begin to add a relationship to the view. Note that you can add relationships for "Content Authored" and "Representative Node" despite the fact that the Node module is uninstalled.
- Add the relationship for "Content Authored" and observe the following error in the view's preview:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'd8_dev.node_field_data' doesn't exist: SELECT users_field_data.created AS users_field_data_created, users_field_data.uid AS uid FROM {users_field_data} users_field_data LEFT JOIN {node_field_data} node_field_data_users_field_data ON users_field_data.uid = node_field_data_users_field_data.uid WHERE (( (users_field_data.status = :db_condition_placeholder_0) )) ORDER BY users_field_data_created DESC LIMIT 11 OFFSET 0; Array ( [:db_condition_placeholder_0] => 1 ) - Remove the relationship added in the last step and add a "Representative Node" relationship to the view. Observe the view admin page blow up with even more errors.
Proposed resolution
Move the "Content Authored" and "Representative Node" view relationship definitions to the node module in a hook_views_data_alter() implementation.
Remaining tasks
Write the code.
User interface changes
The content authored relationship will not be visible in user-based views if the node module is not enabled. The following screenshots of User relationships were taken with the Node module uninstalled.
Before:

After:

API changes
Data model changes
Issue fork drupal-2781815
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:
- 2781815-content-authored-views
changes, plain diff MR !16775
Comments
Comment #2
jelle_sComment #11
catchThis is still valid - node module is optional, user module isn't.
There should be a ticket somewhere to make this generic for entities that implement EntityOwnerInterface, in which case it could move back to user module, but then it would still need to correctly handle modules being enabled or disabled.
Comment #18
danielvezaGiven this a first crack, tests are green.
Comment #19
dcam commentedI didn't find anything to comment about on the MR. The code changes look good to me.
I proceeded to verify the bug. It was pretty easy to replicate, but I rewrote the steps to reproduce the issue based on the experience.
After applying the MR the two invalid relationships are no longer available in the views admin UI when the Node module is uninstalled.
In my opinion this bug qualifies as one that doesn't need regression tests. It checks all of the boxes in the list of reasons why a test might not be needed.
I tested what happens to existing affected views on a site:
I don't know that we need an update function to correct these broken views. I feel like the broken/missing handler warning is preferable to modifying a view. But I don't know what the usual procedure is in this situation. I'm going to proceed with setting this issue to RTBC, but a committer should weigh in on this subject.
Comment #20
dcam commentedBased on what I've seen this doesn't qualify for Major status.
Comment #23
longwaveCommitted and pushed df31ad4e31b to main and 57f0056f0cc to 11.x. Thanks!
Decided not to backport further as this is a niche problem where if users already had this problem in a site they would have worked around it by now, but new sites will not run into it.