Drupal\Core\Database\InvalidQueryException: Query condition 'nid IN ()' cannot be empty

Created on 30 January 2024, 10 months ago
Updated 1 March 2024, 9 months ago

Hello. Firstly, thanks for the module, I think this is a great idea.

Problem / Motivation

If a node URL alias is modified an error is displayed when attempting to view the content listing page. This is because the URL alias no longer matches the URL configured in the taxonomy vocabulary and no matches are returned in content_access_by_path_admin_content_views_query_alter()

Drupal\Core\Database\InvalidQueryException: Query condition 'nid IN ()' cannot be empty. in Drupal\Core\Database\Query\Condition->condition() (line 106 of /var/www/html/web/core/lib/Drupal/Core/Database/Query/Condition.php).

Steps to reproduce

1. add taxonomy term to Content Access by Path vocabulary with URL alias matching the configured node URL alias
2. update the node URL alias to something else
3. attempt to view the content listing page as a user who should have access

Proposed resolution

Update the content_access_by_path textfield to a link field which supports internal links only without an optional title. The URL alias value will be synced in the taxonomy vocabulary if any updates are made on a node level. The link field will also support un-routed URL's for capturing all content that begins with a path e.g. '/news'

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom xiwar

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @xiwar
  • Assigned to xiwar
  • 🇬🇧United Kingdom xiwar
  • 🇬🇧United Kingdom xiwar

    xiwar changed the visibility of the branch content_access_by_path-3418083 to hidden.

  • 🇬🇧United Kingdom xiwar

    xiwar changed the visibility of the branch content_access_by_path-3418083 to hidden.

  • 🇬🇧United Kingdom xiwar

    xiwar changed the visibility of the branch content_access_by_path-3418083 to active.

  • 🇮🇪Ireland markconroy

    Hi @xiwar

    Thanks for reporting this and working on it. I've tried in a number of ways to replicate it but can't. Example:

    1. Create Subsite overview node called "Test Subsite", with URL /test-subsite
    2. Create term called "Test Subsite" in "Content Access by Path" vocabulary, with path test-subsite
    3. Apply this term to a user
    4. Go to /admin/content and see that the only nodes I can edit are my own nodes and the "Test Subsite" node
    5. Edit "Test Subsite" node to call it "My Test Subsite", so the url is /my-test-subsite
    6. Go to /admin/content and see that node is no longer available for editing

  • 🇬🇧United Kingdom xiwar

    Hi @markconroy, thanks for the update.

    I've re-tested this based on your example. I can trigger the error by doing the following.

    As an Admin role

    1. Create Subsite overview node called "Test Subsite", with URL /test-subsite
    2. Create term called "Test Subsite" in "Content Access by Path" vocabulary, with path test-subsite as an admin role. "Content Access by Path" should only contain 1 term
    3. Apply this term to a user. User should only have 1 term configured as above
    4. Go to /admin/content and see that the only nodes I can edit are my own nodes and the "Test Subsite" node
    5. Edit "Test Subsite" node to call it "My Test Subsite", so the url is /my-test-subsite

    As an Editor role

    6. Go to /admin/content and see that the content listing page does not load with the error described in the ticket added to logs.

    After digging into this a bit more, this only happens when there is 1 term mapped to 1 node which the Editor role has access to. If another term is added to the "Content Access by Path" vocabulary with an alias matching one configured on a node the Editor role has access to, the content listing page will load correctly without error.

    In content_access_by_path_admin_content.module line 57, the $matches variables is NULL which triggers the error on line 58 since there are no matches and the Editor role is not the content owner.

    $matches = array_merge($author_owned, $matches);
    $query->addWhere(0, 'nid', $matches, 'IN');
  • 🇮🇪Ireland markconroy

    markconroy changed the visibility of the branch 3418083- to hidden.

  • Merge request !5Resolve #3418083 "No results when null" → (Merged) created by markconroy
  • Status changed to Fixed 9 months ago
  • 🇮🇪Ireland markconroy

    Hi @xiwar

    I tried your branch, but the module wouldn't install from it. Also, I am a little worried without more testing about using Link field. I get that it will work fine for the individual node, but I have a concern about nodes that use the current node as part of their paths without giving it a lot of testing. For example, if you are allowed to edit "Rugby" and the URL is /sport/rugby, will you also be able to edit /sport/rugby/world-cup (as you should be).

    In the mean time, I fixed the specific issue we see (thanks for the detailed report), by:

    1. Checking if $matches[] has a value,
    2. If so, doing the normal thing, and
    3. If not, setting NULL as the query value which forces the empty view message to appear. And then I've amended that view message to "Sorry, there is no content assigned for you to edit."

    I'm going to mark this as fixed and create a new release. It might be good if you think it's worth it to create a follow-up issue titled "Change paths text field to a link field" and we can work on it from there.

  • 🇬🇧United Kingdom xiwar

    Hi @markconroy, that's great, thanks. I'll create a separate issue for this feature.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024