nifty-generators
nifty-generators copied to clipboard
PG::Error: ERROR: zero-length delimited identifier at or near """" -- nifty authentication
Hi,
I'm getting this error on what had been a perfectly functional authentication system using nifty auth.
Could not log "sql.active_record" event. NoMethodError: undefined method `name' for nil:NilClass PG::Error: ERROR: zero-length delimited identifier at or near """" LINE 1: SELECT "users".* FROM "users" WHERE "users"."" = $1 LIMIT
This happens when the current_user method is called. What's odd is that in rails db, this works:
dgap=> select first_name, email from users where id=1; -[ RECORD 1 ]-------------------------------------- first_name | bridget email | [email protected]
but in console I get the same error as above:
ruby -> User.find(1) Could not log "sql.active_record" event. NoMethodError: undefined method `name' for nil:NilClass ActiveRecord::StatementInvalid: PG::Error: ERROR: zero-length delimited identifier at or near """" LINE 1: SELECT "users".* FROM "users" WHERE "users"."" = $1 LIMIT ...
and
ruby -> User
returns the model's attributes.
It's as if it suddenly can't tell what column to id with. All required columns contain values. This started happening after I made a back up of the users table,
dgap => create table users_bak as select * from users;
Then I removed some users:
dgap => delete from users where id > 1;
The user with an id of one is definitely still there.
So I restored the table:
dgap=> alter table users rename to users_borken; dgap=> alter table users_bak rename to users;
and I'm still getting the same errors.
lib/controller_authentication.rb: def current_user @current_user ||= User.find(session[:user_id]) if session[:user_id] end
Untouched.
Thoughts? Any insight would be greatly appreciated.
Steve
Also, if I log out, I can use the site, mostly. It's only after logging in that I'm getting the error reported above. There is a session id, logger.debug "session is #{session}\n\n\n" shows:
session is {"session_id"=>"0513ea4815ba2bd011884ecc59f25014", "_csrf_token"=>"dOqfBdirnnLcGh40hIYyrOGJSHevCqsE/rU3uvDt/6Q="}
However, if I go to ~/users/new I get a new exception:
Unknown primary key for table users in model User. The offending line:
=f.collection_select :area_ids, @areas, :id, :name, {}, { :multiple => true, :size => 9 }
@areas gets set in users controller new.
It seems to have lost sight of the id. But rails c:
ruby -> User.all(:conditions => 'id=1')
works as expected.
UPDATE:
Adding
set_primary_key :id
in models/user.rb solves the problem. But why? That should be unnecessary, and I never needed it before this.
Thanks,
Steve
@cheeby Have you figured out why you needed set_primary_key? I just had the same problem and after adding it, everything works now.
But what the HELL? I never needed it before. Rails is just plain drunk.
@HenleyChiu do you use Spring? Try to stop/restart it and them try again