Open
Description
Description of the bug
Views incorrectly filters out content where an entity reference field is blank in some specific situations. The conditions are:
- The view has a relationship configured to the Referenced Entity.
- A module is enabled that implements "node_grants".
This was originally reported in the content_access issue queue (backdrop-contrib/content_access#30), but I believe it is actually a core issue.
Steps To Reproduce
To reproduce the behavior:
- Setup a Content Type with an entity reference field that targets a node.
- Make sure you have a non-admin (not user 1) account with Bypass content access control permission is disabled.
- Add some content to the content type where some content includes the entity reference and some does not.
- Create a view filtered by the content type setup earlier, displayed as fields in a table. Including the entity reference field.
- Add a Relationship to the view for the Entity Reference - Referenced Entity. Leave the "Require this relationship" unchecked.
- Load the view from the non-admin account. At this point, you should see all content including the nodes with and without the entity reference field populated.
- Enable any module that implements "node_grants", for example, content_access.
- Rebuild Node access permissions.
- Load the view again from the non-admin account.
- This time you will only see the content where the entity reference field is populated. The view should include the nodes where the entity reference field is blank.
Actual behavior
Only the content where the entity reference field is populated is displayed.
Expected behavior
The same content shown in step 6 should be displayed.
Additional information
Add any other information that could help, such as:
- Backdrop CMS version: 1.30.0
- Web server and its version: Apache/2.4.58 (Ubuntu)
- PHP version: 8.3
- Database sever (MySQL or MariaDB?) and its version: 8.0.41-0ubuntu0.24.04.1
- Operating System and its version: Ubuntu 24.04
The views relationship configured to the Referenced Entity causes the following to be appended to the WHERE clause of the Views query:
AND ( EXISTS (SELECT `na`.`nid` AS `nid`
FROM
{node_access} `na`
WHERE (( (`na`.`gid` IN ('0')) AND (`na`.`realm` = 'all') )OR( (`na`.`gid` IN ('2')) AND (`na`.`realm` = 'content_access_author_unpublished') )OR( (`na`.`gid` IN ('2')) AND (`na`.`realm` = 'content_access_author') )OR( (`na`.`gid` IN ('222', '333', '337')) AND (`na`.`realm` = 'content_access_rid') ))AND (`na`.`grant_view` >= '1') AND (node_field_data_field_reference.nid = na.nid) ))
This is only valid when the node_field_data_field_reference.nid is not null.