lynndylanhurley / lynndylanhurley/devise_token_auth
Exception when updating email with existing one
- Dominant language
- Ruby
- Stars
- 3.6k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
When I try to update an User's email with an existing one, I get:
```
ActiveRecord::RecordNotUnique (PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_volunteers_on_uid_and_provider"
```
Why is this exception not handled?
I fixed it with a `before_update` callback in my user model such as:
```
def check_email
user = self.class.find_by(email: self.email)
if user.present? and user.id != self.id
errors.add(:email, "already in use")
return false
end
return true
end
```
But I shouldn't need to do this right?
Contributor guide
Research direction
Start by reproducing an email update against an existing user and trace the update path that reaches the reported PostgreSQL unique constraint. No files or tests are named, so locate the relevant user model and existing validation or error-handling tests first. Done means the duplicate-email update is handled as a validation error rather than an uncaught exception, with regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- api, authentication, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100