jesjos / jesjos/active_record_upsert
ActiveRecord::Base.upsert should return record instead of boolean when validation fails
- Dominant language
- Ruby
- Stars
- 207
- Forks
- 49
- PR merge metrics
- No merged PRs in 30d
Description
In ActiveRecord both `Model.create` and `Model.update` [always return the record](https://github.com/rails/rails/blob/master/activerecord/lib/active_record/persistence.rb#L100-L117) (or a collection of records). Unfortunately `Model.upsert` only returns the record when validations pass. When they fail [it returns `false`](https://github.com/jesjos/active_record_upsert/blob/07bdabf585405143e02bfc7306c2df09b067f847/lib/active_record_upsert/active_record/persistence.rb#L53-L57).
This breaks my expectations on how the API behaves (assuming it mimics ActiveRecord).
While this is an easy thing to change, it's a still major change in terms of the behavior. Code that relies on `false` as the return value will inevitably break once it returns the record.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by comparing activerecord/lib/active_record/persistence.rb around lines 100-117 with lib/active_record_upsert/active_record/persistence.rb around lines 53-57. Verify the validation-failure path and change its return behavior to match the record returned by ActiveRecord; done means invalid upserts return the record rather than false.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- database
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 30/100