Notification claims X users for approval, but none are found

I found this topic while searching before filing a bug report, so adding to it.

TL;DR the query for the notification is wrong because it counts rejected users as well.

Notification: 16 users waiting for approval, click the link, see only 2.

The query used for the notification is this

puts AdminUserIndexQuery.new(query: "pending", stats: false).find_users_query.to_sql

SELECT "users".* FROM "users" 
WHERE (suspended_till IS NULL OR suspended_till <= '2023-11-13 11:05:23.225614') 
AND "users"."approved" = FALSE 
AND "users"."active" = TRUE 
ORDER BY users.created_at DESC,users.username

which, in my case, gives me 16 users

[4479, 4472, 4456, 4446, 4443, 4430, 4302, 4291, 4206, 4199, 4178, 4168, 4131, 4061, 3677, 3642]

Throwing these ids into the Reviewables queue gives me 2 users that actually need to be approved (status 0) and 14 users that have already been rejected (status 2)

ReviewableUser.where(type: 'ReviewableUser')
  .where(target_id: ids)
  .pluck(:target_id, :status)

[[3642, 2], [3677, 2], [4061, 2], [4131, 2], [4168, 2], 
[4178, 2], [4199, 2], [4206, 2], [4291, 2], [4302, 2], 
[4430, 2], [4443, 2], [4446, 2], [4456, 2], [4472, 0], [4479, 0]]
2 Likes