Problem/Motivation

When updating module for security

> [error] Query condition 'uid IN ()' cannot be empty.

due to hook_update_8108

Proposed resolution

Check if variable is not empty before running condition

CommentFileSizeAuthor
#9 fix_query_error.patch691 bytescslevy
Command icon 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:

Comments

maxpah created an issue. See original summary.

jan kellermann’s picture

We did this:

diff --git a/persistent_login.install b/persistent_login.install
index 2ba209f..d524cda 100644
--- a/persistent_login.install
+++ b/persistent_login.install
@@ -245,9 +245,13 @@ function persistent_login_update_8108(&$sandbox) {
     ->condition('uid', $token_users, 'IN')
     ->execute();

-  \Drupal::database()->delete('persistent_login')
-    ->condition('uid', array_diff($token_users, $valid_users), 'IN')
-    ->execute();
+  $to_delete = array_diff($token_users, $valid_users);
+
+  if (!empty($to_delete)) {
+    \Drupal::database()->delete('persistent_login')
+      ->condition('uid', array_diff($token_users, $valid_users), 'IN')
+      ->execute();
+  }

   $sandbox['processed'] += count($token_users);
   $sandbox['current'] = end($token_users);

fenstrat made their first commit to this issue’s fork.

fenstrat’s picture

Status: Active » Needs review

Also hit this, only where uid1 had a persistent login.

The approach from #2 is correct, this should only delete if there's something to delete. I have pushed those changes to an MR.

  • gapple committed cd70fa10 on 8.x-1.x
    Fix #3478340 by jan kellermann, maxpah, fenstrat, gapple: Error on...

  • gapple committed 2720c568 on 2.x
    Fix #3478340 by jan kellermann, maxpah, fenstrat, gapple: Error on...
gapple’s picture

Version: 8.x-1.x-dev » 2.x-dev
Status: Needs review » Fixed

Thanks for the quick patch & review :)

New patch releases should be available shortly.

cslevy’s picture

StatusFileSize
new691 bytes

This still doesn't fix the issue. I attached an extra patch, which also should be included.

andrerb’s picture

Thanks for the patch. I also still had the problem. After the 3rd iteration of the update hook and the query for $token_users, $sandbox[‘current’] was set to the last item in the pl table. Therefore the $token_users array was empty and the following query for $valid_users failed. Patch from #9 fixed the problem.

maxpah’s picture

Status: Fixed » Needs review

Hello !

Thanks for the quick patch and release but this still crash on my side.

Additionnal patch #9 is working.

gapple’s picture

That's odd... On the last iteration $sandbox['#finished'] = $sandbox['processed'] / $sandbox['total']; should equal 1 to complete the batch.
Are there tokens stored for the anonymous user (uid:0)? That would increase $sandbox['total'] to one more than will be returned in the $token_users queries - but that shouldn't happen so some checks might need to be added elsewhere 😬.

  • gapple committed 53a1d813 on 2.x
    Fix #3478340 by cslevy, andrerb, maxpah, gapple: Error on...

  • gapple committed b869a7b9 on 8.x-1.x
    Fix #3478340 by cslevy, andrerb, maxpah, gapple: Error on...
gapple’s picture

Title: Error on hook_update_8108 uid IN ()' cannot be empty » Errors on hook_update_8108
Status: Needs review » Fixed

🤞 that's a final fix for this issue.

Just wanted to also note that the tokens in the database aren't accepted even if provided by a browser, and this cleanup is only really needed for sites with tokens configured to a permanent lifetime, so there isn't a problem if the update is not completed on a site (provided it doesn't block any other necessary updates).

Status: Fixed » Closed (fixed)

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