Stack SQL error after signing in since moving to postgresql database?
This is a pretty weird error bust basically I just moved my app from sqlite3 to postgreSQL. I use the devise ruby gem to handle session management for users. I'm using rails 3.1.0.rc4 and Devise 1.4.2. Anyway, trying to sign in produces this error:
Started POST "/users/sign_in" for 127.0.0.1 at 2011-07-13 11:32:11 +0100
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"tV0DGHLx0vpTz1/1preLrTvNXpm5LpcNsQeWYJGxZcE=", "user"=>{"email"=>"user@user.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
User Load (0.4ms) SELECT DISTINCT "users".id, FROM "users" LEFT OUTER JOIN "memberships" ON "memberships"."member_id" = "users"."id" LEFT OUTER JOIN "teams" ON "teams"."id" = "memberships"."team_id" WHERE "users"."email" = 'user@user.com' LIMIT 1
PGError: ERROR: syntax error at or near "FROM"
LINE 1: SELECT DISTINCT "users".id, FROM "users" LEFT OUTER JOIN "...
^
: SELECT DISTINCT "users".id, FROM "users" LEFT OUTER JOIN "memberships" ON "memberships"."member_id" = "users"."id" LEFT OUTER JOIN "teams" ON "teams"."id" = "memberships"."team_id" WHERE "users"."email" = 'user@user.com' LIMIT 1
Completed 500 Internal Server Error in 187ms
ActiveRecord::StatementInvalid (PGError: ERROR: syntax error at or near "FROM"
LINE 1: SELECT DISTINCT "users".id, FROM "users" LEFT OUTER JOIN "...
^
: SELECT DISTINCT "users".id, FROM "users" LEFT OUTER JOIN "memberships" ON "memberships"."member_id" = "users"."id" LEFT OUTER JOIN "teams" ON "teams"."id" = "memberships"."team_id" WHERE "users"."email" = 'user@user.com' LIMIT 1):
Here's the framework trace:
activerecord (3.1.0.rc4) lib/active_record/connection_adapters/postgresql_adapter.rb:958:in `async_exec'
activerecord (3.1.0.rc4) lib/active_record/connection_adapters/postgresql_adapter.rb:958:in `exec_no_cache'
activerecord (3.1.0.rc4) lib/active_record/connection_adapters/postgresql_adapter.rb:547:in `block in exec_query'
activerecord (3.1.0.rc4) lib/active_record/connection_adapters/abstract_adapter.rb:222:in `block in log'
activesupport (3.1.0.rc4) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activerecord (3.1.0.rc4) lib/active_record/connection_adapters/abstract_adapter.rb:217:in `log'
activerecord (3.1.0.rc4) lib/active_record/connection_adapters/postgresql_adapter.rb:546:in `exec_query'
activerecord (3.1.0.rc4) lib/active_record/connection_adapters/postgresql_adapter.rb:1027:in `select'
activerecord (3.1.0.rc4) lib/active_record/connection_adapters/abstract/database_statements.rb:9:in `select_all'
activerecord (3.1.0.rc4) lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `block in select_all'
activerecord (3.1.0.rc4) lib/active_record/connection_adapters/abstract/query_cache.rb:74:in `cache_sql'
activerecord (3.1.0.rc4) lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all'
activerecord (3.1.0.rc4) lib/active_record/base.rb:473:in `find_by_sql'
activerecord (3.1.0.rc4) lib/active_record/relation.rb:109:in `to_a'
activerecord (3.1.0.rc4) lib/active_record/relation.rb:14:in `collect'
activerecord (3.1.0.rc4) lib/active_record/relation/finder_methods.rb:251:in `construct_limited_ids_condition'
activerecord (3.1.0.rc4) lib/active_record/relation/finder_methods.rb:236:in `apply_join_dependency'
activerecord (3.1.0.rc4) lib/active_record/relation/finder_methods.rb:225:in `construct_relation_for_association_find'
activerecord (3.1.0.rc4) lib/active_record/relation/finder_methods.rb:204:in `find_with_associations'
activerecord (3.1.0.rc4) lib/active_record/relation.rb:109:in `to_a'
activerecord (3.1.0.rc4) lib/active_record/relation.rb:127:in `to_a'
activerecord (3.1.0.rc4) lib/active_record/relation/finder_methods.rb:370:in `find_first'
activerecord (3.1.0.rc4) lib/active_record/relation/finder_methods.rb:122:in `first'
activerecord (3.1.0.rc4) lib/active_record/relation/finder_methods.rb:119:in `first'
activerecord (3.1.0.rc4) lib/active_record/base.rb:444:in `first'
orm_adapter (0.0.5) lib/orm_adapter/adapters/active_record.rb:51:in `find_first'
/Users/davidtuite/.rvm/gems/ruby-1.9.2-head@grouperty/bundler/gems/devise-e9c766277d61/lib/devise/models/authenticatable.rb:109:in `find_for_authentication'
/Users/davidtuite/.rvm/gems/ruby-1.9.2-head@grouperty/bundler/gems/devise-e9c766277d61/lib/devise/models/database_authenticatable.rb:115:in `find_for_database_authentication'
/Users/davidtuite/.rvm/gems/ruby-1.9.2-head@grouperty/bundler/gems/devise-e9c766277d61/lib/devise/strategies/database_authenticatable.rb:8:in `authenticate!'
warden (1.0.4) lib/warden/strategies/base.rb:53:in `_run!'
warden (1.0.4) lib/warden/proxy.rb:311:in `block in _run_strategies_for'
warden (1.0.4) lib/warden/proxy.rb:306:in `each'
warden (1.0.4) lib/warden/proxy.rb:306:in `_run_strategies_for'
warden (1.0.4) lib/warden/proxy.rb:279:in `_perform_authentication'
warden (1.0.4) lib/warden/proxy.rb:113:in `authenticate!'
/Users/davidtuite/.rvm/gems/ruby-1.9.2-head@grouperty/bundler/gems/devise-e9c766277d61/app/controllers/devise/sessions_controller.rb:14:in `create'
actionpack (3.1.0.rc4) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.1.0.rc4) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.1.0.rc4) lib/action_开发者_运维技巧controller/metal/rendering.rb:10:in `process_action'
actionpack (3.1.0.rc4) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.1.0.rc4) lib/active_support/callbacks.rb:434:in `_run__3680065931087317103__process_action__4396720641089604323__callbacks'
activesupport (3.1.0.rc4) lib/active_support/callbacks.rb:386:in `_run_process_action_callbacks'
activesupport (3.1.0.rc4) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.0.rc4) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.1.0.rc4) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.1.0.rc4) lib/active_support/notifications.rb:55:in `block in instrument'
activesupport (3.1.0.rc4) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.1.0.rc4) lib/active_support/notifications.rb:55:in `instrument'
actionpack (3.1.0.rc4) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.1.0.rc4) lib/action_controller/metal/params_wrapper.rb:202:in `process_action'
actionpack (3.1.0.rc4) lib/action_controller/metal/rescue.rb:17:in `process_action'
activerecord (3.1.0.rc4) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.1.0.rc4) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.1.0.rc4) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.1.0.rc4) lib/action_controller/metal.rb:193:in `dispatch'
actionpack (3.1.0.rc4) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.1.0.rc4) lib/action_controller/metal.rb:236:in `block in action'
actionpack (3.1.0.rc4) lib/action_dispatch/routing/route_set.rb:65:in `call'
actionpack (3.1.0.rc4) lib/action_dispatch/routing/route_set.rb:65:in `dispatch'
actionpack (3.1.0.rc4) lib/action_dispatch/routing/route_set.rb:29:in `call'
actionpack (3.1.0.rc4) lib/action_dispatch/routing/mapper.rb:41:in `call'
rack-mount (0.8.1) lib/rack/mount/route_set.rb:152:in `block in call'
rack-mount (0.8.1) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.8.1) lib/rack/mount/code_generation.rb:75:in `optimized_each'
rack-mount (0.8.1) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.8.1) lib/rack/mount/route_set.rb:141:in `call'
actionpack (3.1.0.rc4) lib/action_dispatch/routing/route_set.rb:531:in `call'
warden (1.0.4) lib/warden/manager.rb:35:in `block in call'
warden (1.0.4) lib/warden/manager.rb:34:in `catch'
warden (1.0.4) lib/warden/manager.rb:34:in `call'
actionpack (3.1.0.rc4) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.3.0) lib/rack/etag.rb:23:in `call'
rack (1.3.0) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.1.0.rc4) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.1.0.rc4) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.1.0.rc4) lib/action_dispatch/middleware/flash.rb:243:in `call'
rack (1.3.0) lib/rack/session/abstract/id.rb:195:in `context'
rack (1.3.0) lib/rack/session/abstract/id.rb:190:in `call'
actionpack (3.1.0.rc4) lib/action_dispatch/middleware/cookies.rb:321:in `call'
activerecord (3.1.0.rc4) lib/active_record/query_cache.rb:54:in `call'
activerecord (3.1.0.rc4) lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `call'
actionpack (3.1.0.rc4) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (3.1.0.rc4) lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
activesupport (3.1.0.rc4) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.0.rc4) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
actionpack (3.1.0.rc4) lib/action_dispatch/middleware/reloader.rb:68:in `call'
rack (1.3.0) lib/rack/sendfile.rb:102:in `call'
actionpack (3.1.0.rc4) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.1.0.rc4) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.1.0.rc4) lib/rails/rack/logger.rb:13:in `call'
rack (1.3.0) lib/rack/methodoverride.rb:24:in `call'
rack (1.3.0) lib/rack/runtime.rb:17:in `call'
activesupport (3.1.0.rc4) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.3.0) lib/rack/lock.rb:34:in `call'
actionpack (3.1.0.rc4) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.1.0.rc4) lib/rails/engine.rb:438:in `call'
railties (3.1.0.rc4) lib/rails/rack/content_length.rb:16:in `call'
railties (3.1.0.rc4) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.3.0) lib/rack/handler/webrick.rb:59:in `service'
/Users/davidtuite/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/davidtuite/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/davidtuite/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Is this an ActiveRecord bug or something?
The issue is caused by the fact that I'm trying to eager load teams with users:
class User < ActiveRecord::Base
has_many :teams
default_scope :include => :teams
end
Issue is on Github now. Should be fixed in the next Rails RC.
Can you add in you question information about schema db from db/schema.rb for tables: users, memberships and teams?
精彩评论