fix session context overwrite when logSessionId not set (#2115)
ref pr https://gitea.com/xorm/xorm/pulls/2053 i think the previous fix has some issue for example, i'm using session like this: ```go // logSessionID == false engine := NewEngine() // use ctx.SessionId to distinguish uniq request id cxt := context.WithValue(parent, log.SessionIDKey, "some unique request id") session := engine.NewSession().Context(ctx) ``` however, with pr 2053, `session.Context` can't get SessionId from ctx. this pr fix abrove issue, overwrite `session.Context()` only when `engine.logSessionID == true` please check it out,thanks! Co-authored-by: finelog <kaicltw@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-on: https://gitea.com/xorm/xorm/pulls/2115 Co-authored-by: finelog <finelog@noreply.gitea.io> Co-committed-by: finelog <finelog@noreply.gitea.io>
This commit is contained in:
parent
79a21b68aa
commit
d195040cb9
|
@ -757,7 +757,7 @@ func (session *Session) incrVersionFieldValue(fieldValue *reflect.Value) {
|
||||||
|
|
||||||
// Context sets the context on this session
|
// Context sets the context on this session
|
||||||
func (session *Session) Context(ctx context.Context) *Session {
|
func (session *Session) Context(ctx context.Context) *Session {
|
||||||
if session.ctx != nil {
|
if session.engine.logSessionID && session.ctx != nil {
|
||||||
ctx = context.WithValue(ctx, log.SessionIDKey, session.ctx.Value(log.SessionIDKey))
|
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.SessionKey, session.ctx.Value(log.SessionKey))
|
||||||
ctx = context.WithValue(ctx, log.SessionShowSQLKey, session.ctx.Value(log.SessionShowSQLKey))
|
ctx = context.WithValue(ctx, log.SessionShowSQLKey, session.ctx.Value(log.SessionShowSQLKey))
|
||||||
|
|
Loading…
Reference in New Issue