From df931dfb083a5ffab9815aa9e74d9c969c9b5a02 Mon Sep 17 00:00:00 2001 From: Nils Olofsson Date: Tue, 29 Aug 2023 19:59:45 +0200 Subject: [PATCH] Bug/missing AllowRoot panics no context methods (#227) * Check that methodTracer is not nil before adding it as middleware * Check for when methodTracer is == nil, not != nil --- query.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/query.go b/query.go index 156ca08..3e162ba 100644 --- a/query.go +++ b/query.go @@ -77,10 +77,13 @@ func queryWrapRows(t methodTracer, traceLastInsertID bool, traceRowsAffected boo func makeQueryerContextMiddlewares(r methodRecorder, t methodTracer, cfg queryConfig) []queryContextFuncMiddleware { middlewares := make([]queryContextFuncMiddleware, 0, 3) - middlewares = append(middlewares, - queryStats(r, cfg.metricMethod), - queryTrace(t, cfg.traceQuery, cfg.traceMethod), - ) + middlewares = append(middlewares, queryStats(r, cfg.metricMethod)) + + if t == nil { + return middlewares + } + + middlewares = append(middlewares, queryTrace(t, cfg.traceQuery, cfg.traceMethod)) if cfg.traceRowsNext || cfg.traceRowsClose { middlewares = append(middlewares, queryWrapRows(t, cfg.traceRowsNext, cfg.traceRowsClose))