From 4252c1f7b4a85e0e847e6e9badb81b194faf250b Mon Sep 17 00:00:00 2001 From: guregu Date: Tue, 17 Dec 2024 04:48:57 +0900 Subject: [PATCH] Query.One: delay unmarshaling until success (preserves old behavior) --- query.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/query.go b/query.go index bc6b553..b998e5a 100644 --- a/query.go +++ b/query.go @@ -240,7 +240,8 @@ func (q *Query) One(ctx context.Context, out interface{}) error { // If not, try a Query. iter := q.Iter().(*queryIter) - ok := iter.Next(ctx, out) + var item Item + ok := iter.Next(ctx, &item) if err := iter.Err(); err != nil { return err } @@ -251,7 +252,7 @@ func (q *Query) One(ctx context.Context, out interface{}) error { if iter.hasMore() { return ErrTooMany } - return nil + return unmarshalItem(item, out) } // Count executes this request, returning the number of results.