From 2eccd7cc3016aed9766fae4b5ad51833a60b04ee Mon Sep 17 00:00:00 2001 From: shanyy Date: Mon, 16 Apr 2018 15:59:01 +0800 Subject: [PATCH] Fix failure caused by nil bean --- session_find.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/session_find.go b/session_find.go index 226be5bc..f9dd24ca 100644 --- a/session_find.go +++ b/session_find.go @@ -398,12 +398,19 @@ func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr in bean := cacher.GetBean(tableName, sid) // fix issue #894 - ckb := reflect.ValueOf(bean).Elem().Type() - ht := ckb == t - if !ht && t.Kind() == reflect.Ptr { - ht = t.Elem() == ckb + isHit := func() (ht bool) { + if bean == nil { + ht = false + return + } + ckb := reflect.ValueOf(bean).Elem().Type() + ht = ckb == t + if !ht && t.Kind() == reflect.Ptr { + ht = t.Elem() == ckb + } + return } - if bean == nil || !ht { + if !isHit() { ides = append(ides, id) ididxes[sid] = idx } else {