Skip to content

Commit

Permalink
fix(types): make UnwrapSDKContext work after context.WithValue (#11341)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronc committed Mar 11, 2022
1 parent f4d50a9 commit 25feb23
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ func (c Context) WithValue(key, value interface{}) Context {
}

func (c Context) Value(key interface{}) interface{} {
if key == SdkContextKey {
return c
}

return c.baseCtx.Value(key)
}

Expand Down
5 changes: 5 additions & 0 deletions types/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,9 @@ func (s *contextTestSuite) TestUnwrapSDKContext() {

ctx = context.Background()
s.Require().Panics(func() { types.UnwrapSDKContext(ctx) })

// test unwrapping when we've used context.WithValue
ctx = context.WithValue(sdkCtx, "foo", "bar")
sdkCtx2 = types.UnwrapSDKContext(ctx)
s.Require().Equal(sdkCtx, sdkCtx2)
}

0 comments on commit 25feb23

Please sign in to comment.