jesjos / jesjos/active_record_upsert

Updates to an upserted record are not applied

Open
#96 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
207
Forks
49
PR merge metrics
No merged PRs in 30d

Description

After upserting, the very next save on the resulting record does not persist

```ruby
MyModel.find_by(uuid: 1234) # nil

record = MyModel.new # (id, uuid, name, age)
record.uuid = 1234 # uuid is the upsert_key
result = record.upsert # creates record with uuid 1234

result.update(name: "foo")

persisted = MyModel.find_by(uuid: 1234)
persisted.name # nil

result.update(age: 42)

persisted = MyModel.find_by(uuid: 1234)
persisted.age # 42
```

The first upsert does an `INSERT ON CONFLICT` generating the record
The very next update tries to update every column `UPDATE "my_model" SET "id" = $1, "name" = $2 ...`
Then the update after that does the usual `UPDATE "my_model" SET "age" = $1 ...`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the upsert flow that creates the record, then inspect how the resulting record tracks persisted attributes before the first update. Reproduce the example in the issue and verify that the first result.update(name: "foo") persists name, while the later age update continues to persist normally.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.