From 0de285680bed16dacdf63a755d32d0edf0a5b794 Mon Sep 17 00:00:00 2001 From: undefined_ss Date: Thu, 23 Sep 2021 20:22:14 +0800 Subject: [PATCH] fix ctx override bug (#2053) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 详情请参考工单:https://gitea.com/xorm/xorm/issues/2052 Co-authored-by: undefined_ss Reviewed-on: https://gitea.com/xorm/xorm/pulls/2053 Reviewed-by: Lunny Xiao Co-authored-by: undefined_ss Co-committed-by: undefined_ss --- session.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/session.go b/session.go index f5b45a73..f51fd41b 100644 --- a/session.go +++ b/session.go @@ -732,6 +732,12 @@ func (session *Session) incrVersionFieldValue(fieldValue *reflect.Value) { // Context sets the context on this session func (session *Session) Context(ctx context.Context) *Session { + if session.ctx != nil { + ctx = context.WithValue(ctx, log.SessionIDKey, session.ctx.Value(log.SessionIDKey)) + ctx = context.WithValue(ctx, log.SessionKey, session.ctx.Value(log.SessionKey)) + ctx = context.WithValue(ctx, log.SessionShowSQLKey, session.ctx.Value(log.SessionShowSQLKey)) + } + session.ctx = ctx return session }