Skip to content

Commit

Permalink
Query.One: delay unmarshaling until success (preserves old behavior)
Browse files Browse the repository at this point in the history
  • Loading branch information
guregu committed Dec 16, 2024
1 parent a1cf2dc commit 4252c1f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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.
Expand Down

0 comments on commit 4252c1f

Please sign in to comment.