From 8fb459dc48dadbbc7da61ef16448f27e8c408810 Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Sat, 5 Feb 2022 18:48:41 +0530 Subject: [PATCH] Fix custom DB type scan failing when nil. --- models/models.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/models/models.go b/models/models.go index 402c672c..9388c08c 100644 --- a/models/models.go +++ b/models/models.go @@ -325,6 +325,11 @@ func (s SubscriberAttribs) Value() (driver.Value, error) { // Scan unmarshals JSONB from the DB. func (s SubscriberAttribs) Scan(src interface{}) error { + if src == nil { + s = make(SubscriberAttribs) + return nil + } + if data, ok := src.([]byte); ok { return json.Unmarshal(data, &s) } @@ -333,6 +338,11 @@ func (s SubscriberAttribs) Scan(src interface{}) error { // Scan unmarshals JSONB from the DB. func (s StringIntMap) Scan(src interface{}) error { + if src == nil { + s = make(StringIntMap) + return nil + } + if data, ok := src.([]byte); ok { return json.Unmarshal(data, &s) }