fix(orm): ValidateJSON fails when tables are missing (#11174)
This commit is contained in:
parent
d98503b21f
commit
94e6a379a2
@ -42,6 +42,10 @@ func (m moduleDB) ValidateJSON(source ormjson.ReadSource) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if r == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
err = table.ValidateJSON(r)
|
||||
if err != nil {
|
||||
errMap[name] = err
|
||||
|
||||
@ -245,12 +245,20 @@ func TestModuleDB(t *testing.T) {
|
||||
rawJson, err = target.JSON()
|
||||
assert.NilError(t, err)
|
||||
|
||||
goodJSON := `{
|
||||
"testpb.Supply": []
|
||||
}`
|
||||
source, err := ormjson.NewRawMessageSource(json.RawMessage(goodJSON))
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(t, db.ValidateJSON(source))
|
||||
assert.NilError(t, db.ImportJSON(ormtable.WrapContextDefault(ormtest.NewMemoryBackend()), source))
|
||||
|
||||
badJSON := `{
|
||||
"testpb.Balance": 5,
|
||||
"testpb.Supply": {}
|
||||
}
|
||||
`
|
||||
source, err := ormjson.NewRawMessageSource(json.RawMessage(badJSON))
|
||||
source, err = ormjson.NewRawMessageSource(json.RawMessage(badJSON))
|
||||
assert.NilError(t, err)
|
||||
assert.ErrorIs(t, db.ValidateJSON(source), ormerrors.JSONValidationError)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user