From 0305dde964e5f21a84087b55d7c6899107543b4b Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Sat, 6 May 2017 17:01:41 -0400 Subject: [PATCH] database/models: MetadataMap decodes from string github.com/lib/pq began decoding text-like fields as strings to Scanners. See lib/pq@e2402a7cd1e57e08a576b94cdfed36ae30366545 --- database/models.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/database/models.go b/database/models.go index 2d645e6c..2c304e80 100644 --- a/database/models.go +++ b/database/models.go @@ -83,11 +83,16 @@ type Vulnerability struct { type MetadataMap map[string]interface{} func (mm *MetadataMap) Scan(value interface{}) error { - val, ok := value.([]byte) - if !ok { + if value == nil { return nil } - return json.Unmarshal(val, mm) + + // github.com/lib/pq decodes TEXT/VARCHAR fields into strings. + val, ok := value.(string) + if !ok { + panic("got type other than []byte from database") + } + return json.Unmarshal([]byte(val), mm) } func (mm *MetadataMap) Value() (driver.Value, error) {