columbusrb / conclave

Soon to be the greatest web forum EVER DEVISED.
http://conclaveapp.herokuapp.com/
17 stars 14 forks source link

PostgreSQL Error on ip_ban_check #99

Closed cashby closed 11 years ago

cashby commented 11 years ago

I'm successfully running Conclave on Heroku. I can use seeded User accounts and Admin can create new User accounts without errors. When I try to create a new User account through Sign Up with email and password, Postsgres throws an error.

It looks like Postgres is having an issue reading the true/false boolean syntax.

2012-10-18T09:10:31+00:00 app[web.1]:   app/controllers/application_controller.rb:20:in `check_for_banned_user'
2012-10-18T09:10:31+00:00 app[web.1]: 
2012-10-18T09:10:31+00:00 app[web.1]: ActiveRecord::StatementInvalid (PG::Error: ERROR:  syntax error at or near "'t'"
2012-10-18T09:10:31+00:00 app[web.1]: : SELECT last_sign_in_ip FROM "users"  WHERE (banned is 't')):
2012-10-18T09:10:31+00:00 app[web.1]: LINE 1: SELECT last_sign_in_ip FROM "users"  WHERE (banned is 't')
2012-10-18T09:10:31+00:00 app[web.1]:                                                               ^
2012-10-18T09:10:31+00:00 app[web.1]:   app/models/ip_ban_check.rb:11:in `banned?'
2012-10-18T09:10:31+00:00 app[web.1]:   app/controllers/application_controller.rb:42:in `ip_ban_check'

Here is the method in ip_ban_check.rb referenced in the error:

def banned?
  banned_users.pluck(:last_sign_in_ip).compact.uniq.include?(ip)
end

Here is the method in application_controller.rb referenced in the error:

  def ip_ban_check(ip)
    ip = IPBanCheck.new(ip)
    ip.unban! if ip.banned? && ip.ban_over?
    ip.banned?
  end

Heroku gives the "We're sorry, but something went wrong" error. It does not give the redirect_banned_user alert or any other message from one of the controllers.

This error actually crashes the entire Heroku app. I still get the "We're sorry, but something went wrong" error at the root path and every other path. When I restart the app, the error is still there.

Once I destroy the User from the Heroku Console, I can then restart the app and it runs fine again.

Here is the User record.

irb(main):002:0* User.last
  User Load (1.6ms)  SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
=> #<User id: 6, email: "chip.ashby@columbusfijis.com", encrypted_password: "$2a$10$uDf4Ks8QOGOKXKv9aYAnzeJ66dV3jQm0M5NCLNHdkzZ5...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2012-10-18 09:10:30", last_sign_in_at: "2012-10-18 09:10:30", current_sign_in_ip: "75.118.133.31", last_sign_in_ip: "75.118.133.31", created_at: "2012-10-18 09:10:30", updated_at: "2012-10-18 09:10:30", role: "contributor", nickname: nil, provider: nil, secret: nil, token: nil, uid: nil, banned: false, banned_at: nil, banned_until: nil>
skord commented 11 years ago

We've got 99 isssues and a ban ain't one!

skord commented 11 years ago

What's the output of

heroku info |grep -i stack

and

heroku run rake db:migrate:status
skord commented 11 years ago

And

heroku pg

Please.

cashby commented 11 years ago
[conclave(master)]$ heroku info |grep -i stack
Stack:         cedar
[conclave(master)]$ heroku run rake db:migrate:status
Running `rake db:migrate:status` attached to terminal... up, run.1
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)

database: d8tkuicu75d2mj

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20120919002926  Devise create users
   up     20120919174618  Add role to users
   up     20120919175956  Create admin notes
   up     20120919175957  Move admin notes to comments
   up     20120921195653  Create comments and conversation
   up     20120921204724  Create forums
   up     20120925023432  Add creator id to conversations
   up     20120925225547  Add timestamps to conversation
   up     20120926125509  Add comment counter cache to conversations
   up     20120926133429  Add fake timestamps to conversations
   up     20121001143615  Create admin settings
   up     20121001150930  Create uploaded files
   up     20121001190703  Add omni auth fields to user
   up     20121002134344  Create banishments
   up     20121002144000  Remove users ip field
   up     20121003134339  Add conversation counter to forum
   up     20121003190519  Add watches
   up     20121008202253  Add redacted fields to comments
   up     20121015154100  Create read marks
[conclave(master)]$ heroku pg
=== HEROKU_POSTGRESQL_AMBER_URL (DATABASE_URL)
Plan:        Dev
Status:      available
Connections: 0
PG Version:  9.1.6
Created:     2012-10-17 12:46 UTC
Data Size:   6.5 MB
Tables:      10
Rows:        0/10000 (In compliance)
Fork/Follow: Unavailable
mdarby commented 11 years ago

I've got a bead on this one -- give me a minute.

mdarby commented 11 years ago

The fix is in fdab8b8 -- please let me know if this fixes the issue. (Postgres chokes on my usual way of crafting scopes).

cashby commented 11 years ago

Thank you Matt and Mike. That fixed it!