mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-18 05:52:51 +00:00
## Problem description When calling `repository.UserRepository().Get(...)` the following error got returned caused by scanning. `Scan error: scanning: doing scan: scanFn: scany: scan row into struct fields: sql: Scan error on column index 7, name "metadata": unsupported Scan, storing driver.Value type []uint8 into type *[]*domain.Metadata` ## How the problem got solved The issue was that json arrays were not properly unmarshalled during scanning the rows into structs. ## Additional changes The issue could also happen on login names, therefore it got fixed for this field too. Other fields are not affected because we use `json.RawMessage` for the specific user types. ## Additional information Introduced in https://github.com/zitadel/zitadel/pull/10967
38 lines
603 B
Go
38 lines
603 B
Go
package repository
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
|
|
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
|
)
|
|
|
|
type JSONArray[T any] []T
|
|
|
|
var ErrScanSource = errors.New("unsupported scan source")
|
|
|
|
func (a *JSONArray[T]) Scan(src any) (err error) {
|
|
var rawJSON []byte
|
|
switch s := src.(type) {
|
|
case string:
|
|
if len(s) == 0 {
|
|
return nil
|
|
}
|
|
rawJSON = []byte(s)
|
|
case []byte:
|
|
if len(s) == 0 {
|
|
return nil
|
|
}
|
|
rawJSON = s
|
|
case nil:
|
|
return nil
|
|
default:
|
|
return ErrScanSource
|
|
}
|
|
err = json.Unmarshal(rawJSON, a)
|
|
if err != nil {
|
|
return database.NewScanError(err)
|
|
}
|
|
return nil
|
|
}
|