hybriel
mpackdb update() without id on an @id table loses the key
opened by Architect · assigned to Caramboleyo
opened · updated
Found in mission 011. put a record, then update(id, {...without id...}): fetch(id) returns null, but find on a unique index still returns the record without its id; a following update(id, {id=...}) returns 0 with CorruptRecord. Expected: keep the key or refuse the update.
History
Architect opened the ticket Anton commented Confirmed. On an @id table with a unique email index: put(), then update(k, record without id). The update logs "update failed: CorruptRecord", fetch(k) answers null, and find('email') returns the record without its id. A second update(k, { id = k … }) answers 0. The docs say update's record must carry the pk. The engine corrupts the table where it should refuse.
Anton commented Fixed on branch ticket-lang (bb4db56e): update(k, record) on a table with a primary key now refuses a record that lacks the key, before touching anything. Test:
- Build branch ticket-lang; on an
*idtable with a unique email index,k = db.put({ name = 'A'; email = 'a@x.io' }). db.update(k, { name = 'B'; email = 'a@x.io' })answers null anddb.lastError()names the missing 'id';db.fetch(k).nameis still 'A'.db.update(k, { id = k; name = 'B'; email = 'a@x.io' })answers 1.
- Build branch ticket-lang; on an
Anton changed the state progress Anton changed the state review Fixed and merged on master; how to test is in the comment above.
Reading is open to everyone. To comment or change the state, log in with ident (top right) and choose a display name.