Closed aaronskiba closed 1 month ago
3.1.4 :001 > User.find_by!(email: 'test@abc.com')
User Load (3.9ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 LIMIT $2 [["email", "test@abc.com"], ["LIMIT", 1]]
=> #<User id: 26479, firstname: "test", surname: "test", email: "test@abc.com", created_at: "2024-10-10 17:13:10.783440000 +0000", updated_at: "2024-10-10 17:13:10.783440000 +0000", other_organisation: nil, dmponline3: nil, accept_terms: true, org_id: 59, api_token: nil, language_id: 1, recovery_email: nil, active: true, department_id: nil, last_api_access: nil, prefs:
3.1.4 :002 > user = User.find_or_initialize_by(email: 'Test@abc.com')
User Load (3.8ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 LIMIT $2 [["email", "Test@abc.com"], ["LIMIT", 1]]ise.friendly_token[0, 20])
Language Load (2.2ms) SELECT "languages".* FROM "languages" WHERE "languages"."default_language" = $1 ORDER BY "languages"."id" ASC LIMIT $2 [["default_language", true], ["LIMIT", 1]]
3.1.4 :003 > user.new_record?
=> true
3.1.4 :004 > user.update!(firstname: 'test', surname: 'test', org: Org.find_by(is_other: true), accept_terms: true, password
: Devise.friendly_token[0, 20])
Org Load (3.2ms) SELECT "orgs".* FROM "orgs" WHERE "orgs"."is_other" = $1 LIMIT $2 [["is_other", true], ["LIMIT", 1]]
TRANSACTION (2.9ms) BEGIN
User Exists? (2.1ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = $1 LIMIT $2 [["email", "test@abc.com"], ["LIMIT", 1]]
Language Load (1.0ms) SELECT "languages".* FROM "languages" WHERE "languages"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
TRANSACTION (2.7ms) ROLLBACK
/usr/share/rvm/gems/ruby-3.1.4/gems/activerecord-6.1.7.8/lib/active_record/validations.rb:80:in `raise_validation_error': Validation failed: Email has already been taken (ActiveRecord::RecordInvalid)
The error seems to be caused due User.find_or_initialize_by()
being case-sensitive when querying the email but user.update!()
being case-insensitive (by applying .downcase
) when saving the email.
View details in Rollbar: https://app.rollbar.com/a/ualbertalib/fix/item/dmp_assistant/534