From 8b3094e95bf633048c6a8221695b8b57655f570f Mon Sep 17 00:00:00 2001 From: Elijah Parker <114941210+eparker-tulip@users.noreply.github.com> Date: Thu, 3 Oct 2024 10:40:57 -0500 Subject: [PATCH] Correction for objectID issue in last merge (#86) The last PR merged decode the objectID as either string or objectId type, but would fail on binary objectIDs. The prior implementation had converted the objectID to an interface{} type, to be handled downstream, so this moves back to that approach, while still limiting the unmarshaling to just the _id field. --- default.nix | 2 +- lib/oplog/tail.go | 18 +++++------------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/default.nix b/default.nix index 7bb8f37..5d113c1 100644 --- a/default.nix +++ b/default.nix @@ -2,7 +2,7 @@ buildGoModule { pname = "oplogtoredis"; - version = "3.7.0"; + version = "3.7.1"; src = builtins.path { path = ./.; }; postInstall = '' diff --git a/lib/oplog/tail.go b/lib/oplog/tail.go index 36242ea..84e6da3 100644 --- a/lib/oplog/tail.go +++ b/lib/oplog/tail.go @@ -510,21 +510,13 @@ func (tailer *Tailer) parseRawOplogEntry(entry rawOplogEntry, txIdx *uint) []opl } else { idLookup := entry.Doc.Lookup("_id") if idLookup.IsZero() { - log.Log.Errorf("failed to get objectId: _id is empty or not set") + log.Log.Error("failed to get objectId: _id is empty or not set") return nil } - oid, ok := idLookup.ObjectIDOK() - if ok { - // this is left as ObjectID type for now so it can be properly converted in processor.go:56 - out.DocID = oid - } else { - oidString, ok := idLookup.StringValueOK() - if ok { - out.DocID = oidString - } else { - log.Log.Errorf("failed to get objectId: _id is not ObjectID or String type") - return nil - } + err := idLookup.Unmarshal(&out.DocID) + if err != nil { + log.Log.Errorf("failed to unmarshal objectId: %v", err) + return nil } }