User.find_by(id: 123) fails: no login, no adminstration

#1

We have some users where the profile page is visible, but neither login works for them nor can I administer them. It always results in a 404 page.

I went to the rails console and tried to look up the user by id and username:

[2] pry(main)> User.find_by(id: 2)
=> nil
[3] pry(main)> User.find_by(username_lower: "juanettedoe")
=> #<User:0x00005622930e5770
 id: 2,
 username: "juanettedoe",
 …

So, looking up via username works and it reveals the correct user id. But, looking up by user id does not result in the dataset. What can I do about it?

(Michael Brown) #2

This makes me think that your postgres indices are corrupt.

I would recommend first following the steps listed on Corruption - PostgreSQL wiki to preserve your data.

After you’ve made a copy if you run the postgres CLI and try that same underlying query you should results like:

discourse_development=# SELECT  "users"."id", "users"."username" FROM "users" WHERE "users"."id" = 2 LIMIT 1;
 id | username 
----+-------------
  2 | juanettedoe
(1 row)

discourse_development=# SELECT  "users"."id", "users"."username" FROM "users" WHERE "users"."username_lower" = 'juanettedoe' LIMIT 1;
 id | username 
----+-------------
  2 | juanettedoe
(1 row)
5 Likes
#3

Thanks, I’ll check this out!

1 Like
#4

Indeed it was an index corruption issue. I think i sorted it out – thanks!

4 Likes