Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PG::UndefinedColumn: ERROR: column "email" does not exist. #10

Closed
tiagocassio opened this issue Aug 4, 2018 · 4 comments
Closed

PG::UndefinedColumn: ERROR: column "email" does not exist. #10

tiagocassio opened this issue Aug 4, 2018 · 4 comments

Comments

@tiagocassio
Copy link

Hi, i'm using this gem to obfuscate some user data including email.

Then, when im trying to retrieve the user through default devise controller using devise_token_auth gem, i'm getting this error:

PG::UndefinedColumn: ERROR: column "email" does not exist.

Interresting that when i retrieve the user by rails console, the error does not appears. What's going on?

This is my model configuration:

attr_encrypted :email, key: Base64.decode64(Rails.application.credentials.encryption_key)
blind_index :email, key: Base64.decode64(Rails.application.credentials.blind_index_key)

And this is my database migration:

add_column :users, :encrypted_email, :string
add_column :users, :encrypted_email_iv, :string
add_column :users, :encrypted_email_bidx, :string
remove_column :users, :email

Thanks for the support.

@ankane
Copy link
Owner

ankane commented Aug 4, 2018

Hey @tiagocassio, I haven't used the devise_token_auth, but there's a chance it doesn't work with attr_encrypted/blind_index. Can you paste the full backtrace for the error?

@tiagocassio
Copy link
Author

tiagocassio commented Aug 4, 2018

Hi @ankane, Thanks for the reply. See the stack below:

Started POST "/auth/sign_in" for ::1 at 2018-08-04 20:05:59 -0300
Processing by DeviseTokenAuth::SessionsController#create as HTML
  Parameters: {"email"=>"[FILTERED]", "password"=>"[FILTERED]"}
  �[1m�[36mUser Load (1.1ms)�[0m  �[1m�[34mSELECT  "users".* FROM "users" WHERE (email = '[FILTERED]' AND provider='email') ORDER BY "users"."id" ASC LIMIT $1�[0m  [["LIMIT", 1]]
  ↳ /home/cassio/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/log_subscriber.rb:98
Completed 500 Internal Server Error in 8ms (ActiveRecord: 4.9ms)

ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR:  column "email" does not exist
LINE 1: SELECT  "users".* FROM "users" WHERE (email = 'tiagocassio@o...
                                              ^
: SELECT  "users".* FROM "users" WHERE (email = '[FILTERED]' AND provider='email') ORDER BY "users"."id" ASC LIMIT $1):
  
rack-mini-profiler (1.0.0) lib/patches/db/pg.rb:95:in `exec'
rack-mini-profiler (1.0.0) lib/patches/db/pg.rb:95:in `async_exec'
activerecord (5.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:603:in `block (2 levels) in exec_no_cache'
activesupport (5.2.0) lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
activesupport (5.2.0) lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
activesupport (5.2.0) lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
activerecord (5.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:602:in `block in exec_no_cache'
activerecord (5.2.0) lib/active_record/connection_adapters/abstract_adapter.rb:579:in `block (2 levels) in log'
/home/cassio/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
activerecord (5.2.0) lib/active_record/connection_adapters/abstract_adapter.rb:578:in `block in log'
activesupport (5.2.0) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activerecord (5.2.0) lib/active_record/connection_adapters/abstract_adapter.rb:569:in `log'
activerecord (5.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:601:in `exec_no_cache'
activerecord (5.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:590:in `execute_and_clear'
activerecord (5.2.0) lib/active_record/connection_adapters/postgresql/database_statements.rb:81:in `exec_query'
activerecord (5.2.0) lib/active_record/connection_adapters/abstract/database_statements.rb:465:in `select'
activerecord (5.2.0) lib/active_record/connection_adapters/abstract/database_statements.rb:57:in `select_all'
activerecord (5.2.0) lib/active_record/connection_adapters/abstract/query_cache.rb:99:in `block in select_all'
activerecord (5.2.0) lib/active_record/connection_adapters/abstract/query_cache.rb:122:in `block in cache_sql'
/home/cassio/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
activerecord (5.2.0) lib/active_record/connection_adapters/abstract/query_cache.rb:108:in `cache_sql'
activerecord (5.2.0) lib/active_record/connection_adapters/abstract/query_cache.rb:99:in `select_all'
activerecord (5.2.0) lib/active_record/querying.rb:41:in `find_by_sql'
bullet (5.7.5) lib/bullet/active_record52.rb:25:in `find_by_sql'
activerecord (5.2.0) lib/active_record/relation.rb:554:in `block in exec_queries'
activerecord (5.2.0) lib/active_record/relation.rb:578:in `skip_query_cache_if_necessary'
activerecord (5.2.0) lib/active_record/relation.rb:542:in `exec_queries'
activerecord (5.2.0) lib/active_record/relation.rb:414:in `load'
activerecord (5.2.0) lib/active_record/relation.rb:200:in `records'
bullet (5.7.5) lib/bullet/active_record52.rb:50:in `records'
activerecord (5.2.0) lib/active_record/relation.rb:195:in `to_ary'
activerecord (5.2.0) lib/active_record/relation/finder_methods.rb:530:in `find_nth_with_limit'
activerecord (5.2.0) lib/active_record/relation/finder_methods.rb:515:in `find_nth'
activerecord (5.2.0) lib/active_record/relation/finder_methods.rb:125:in `first'
devise_token_auth (0.1.43) app/controllers/devise_token_auth/concerns/resource_finder.rb:27:in `find_resource'
devise_token_auth (0.1.43) app/controllers/devise_token_auth/sessions_controller.rb:19:in `create'
actionpack (5.2.0) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (5.2.0) lib/abstract_controller/base.rb:194:in `process_action'
actionpack (5.2.0) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.2.0) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (5.2.0) lib/active_support/callbacks.rb:132:in `run_callbacks'
actionpack (5.2.0) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (5.2.0) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (5.2.0) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
activesupport (5.2.0) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.0) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.0) lib/active_support/notifications.rb:168:in `instrument'
actionpack (5.2.0) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (5.2.0) lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
activerecord (5.2.0) lib/active_record/railties/controller_runtime.rb:24:in `process_action'
actionpack (5.2.0) lib/abstract_controller/base.rb:134:in `process'
actionpack (5.2.0) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (5.2.0) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (5.2.0) lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
actionpack (5.2.0) lib/action_dispatch/routing/route_set.rb:34:in `serve'
actionpack (5.2.0) lib/action_dispatch/routing/mapper.rb:18:in `block in <class:Constraints>'
actionpack (5.2.0) lib/action_dispatch/routing/mapper.rb:48:in `serve'
actionpack (5.2.0) lib/action_dispatch/journey/router.rb:52:in `block in serve'
actionpack (5.2.0) lib/action_dispatch/journey/router.rb:35:in `each'
actionpack (5.2.0) lib/action_dispatch/journey/router.rb:35:in `serve'
actionpack (5.2.0) lib/action_dispatch/routing/route_set.rb:840:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
bullet (5.7.5) lib/bullet/rack.rb:14:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
warden (1.2.7) lib/warden/manager.rb:36:in `block in call'
warden (1.2.7) lib/warden/manager.rb:35:in `catch'
warden (1.2.7) lib/warden/manager.rb:35:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
rack (2.0.5) lib/rack/etag.rb:25:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
rack (2.0.5) lib/rack/conditional_get.rb:38:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
rack (2.0.5) lib/rack/head.rb:12:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
activerecord (5.2.0) lib/active_record/migration.rb:559:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (5.2.0) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (5.2.0) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/executor.rb:14:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
railties (5.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.0) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:28:in `tagged'
logstop (0.2.3) lib/logstop/formatter.rb:16:in `method_missing'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.0) lib/rails/rack/logger.rb:26:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/request_id.rb:27:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/action_dispatch/request_id.rb:12:in `call'
rack (2.0.5) lib/rack/runtime.rb:22:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
activesupport (5.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/executor.rb:14:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/static.rb:127:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
rack (2.0.5) lib/rack/sendfile.rb:111:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
honeybadger (3.3.0) lib/honeybadger/rack/error_notifier.rb:33:in `block in call'
honeybadger (3.3.0) lib/honeybadger/agent.rb:337:in `with_rack_env'
honeybadger (3.3.0) lib/honeybadger/rack/error_notifier.rb:30:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
honeybadger (3.3.0) lib/honeybadger/rack/user_feedback.rb:31:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
honeybadger (3.3.0) lib/honeybadger/rack/user_informer.rb:21:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
rack-mini-profiler (1.0.0) lib/mini_profiler/profiler.rb:285:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
rack-cors (1.0.2) lib/rack/cors.rb:97:in `call'
skylight-core (2.0.2) lib/skylight/core/probes/middleware.rb:29:in `call'
railties (5.2.0) lib/rails/engine.rb:524:in `call'
puma (3.12.0) lib/puma/configuration.rb:225:in `call'
puma (3.12.0) lib/puma/server.rb:658:in `handle_request'
puma (3.12.0) lib/puma/server.rb:472:in `process_client'
puma (3.12.0) lib/puma/server.rb:332:in `block in run'
puma (3.12.0) lib/puma/thread_pool.rb:133:in `block in spawn_thread'
** [Honeybadger] Unable to send error report: API key is missing. id=250a0fca-a443-437a-bf4a-21dee5d35ee7 level=3 pid=14536

@ankane
Copy link
Owner

ankane commented Aug 5, 2018

It looks like devise_token_auth uses a string for queries instead of a symbol - where("email = ?", value) instead of where(email: value) - so it won't work without monkey patching that method.

@tiagocassio
Copy link
Author

Okay, i will find a way to override this method, thanks for help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants