Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #11 from zph/debug-deletes
Browse files Browse the repository at this point in the history
Fix DELETE actions being broken due to missing _id
  • Loading branch information
zph authored Aug 31, 2018
2 parents d7d0e73 + 492556f commit ff9903f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 2 additions & 4 deletions tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,8 @@ func (t *Tailer) processOp(op *gtm.Op, workerType string) {
logFn(s, err)
case op.IsDelete() && t.env.allowDeletes:
t.counters.delete.Incr(1)
// Deletes have empty op.Data
// We patch in the op.Id instead for consistent data
// Bad idea? Should we always rely on op.ID? instead?
s, err := t.pg.NamedExec(o.BuildDelete(), data)
deleteSQL := o.BuildDelete()
s, err := t.pg.NamedExec(deleteSQL, data)
logFn(s, err)
}
}
Expand Down
13 changes: 9 additions & 4 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ func SanitizeData(pgFields Fields, op *gtm.Op) map[string]interface{} {
if err != nil {
log.Errorf("Failed to marshal op.Data into json %s", err.Error())
}
// Normalize data map to always include the Id with conversion
if op.Id != nil {
output["_id"] = op.Id
}

for k, v := range pgFields {
// Dot notation extraction
Expand All @@ -156,6 +152,15 @@ func SanitizeData(pgFields Fields, op *gtm.Op) map[string]interface{} {
}
}
}

// Normalize data map to always include the Id with conversion
// Required for delete actions that have a missing _id field in
// op.Data. Must occur after the preceeding iterative block
// in order to avoid being overwritten with nil.
if op.Id != nil {
output["_id"] = op.Id
}

return output
}

Expand Down

0 comments on commit ff9903f

Please sign in to comment.