alaveteli icon indicating copy to clipboard operation
alaveteli copied to clipboard

rake cleanup:spam_users aborts due to ActiveRecord::StatementInvalid

Open nigeljonez opened this issue 5 years ago • 2 comments

Hi!

As part of FYI's prep work to get fully up to date we've started going through testing with a clone of our production DB to look for potential gotchas, as part of it I've noticed that the cleanup:spam_users rake task no longer appears to work.

root@84b7353fca7e:/opt/alaveteli# bundle exec rake cleanup:spam_users
rake aborted!
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "info_requests"
LINE 1: SELECT  "users".* FROM "users" WHERE (info_requests.user_id ...
                                              ^
: SELECT  "users".* FROM "users" WHERE (info_requests.user_id IS NULL
             AND about_me LIKE '%http%'
             AND ban_text = ''
             AND confirmed_not_spam = 'f') ORDER BY "users"."id" ASC LIMIT $1
[...]

Caused by:
PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "info_requests"
LINE 1: SELECT  "users".* FROM "users" WHERE (info_requests.user_id ...

Looking at https://github.com/mysociety/alaveteli/blob/4a1b5faeb2b2ddb7c973436ffedc28241004f5d8/lib/tasks/cleanup.rake#L26-L33 I'm wondering if this syntax is perhaps not valid with Rails 5 but was with 4. That said, if the intention is what I think it is, would the following (assuming the population of the column has occurred) not give the same result?

    User.where("info_requests_count = 0
             AND about_me LIKE '%http%'
             AND ban_text = ''
             AND confirmed_not_spam = ?", false).
        order("users.created_at DESC").find_each do |user|
          results[user.id] = spam_scorer.score(user)
    end

This appears to work in the console.

If this seems on the face of it correct, will happily send through a PR but want to check before hand to ensure I'm not missing something obvious.

nigeljonez avatar Jul 21 '19 05:07 nigeljonez