[#6281] fixed unique validator error
This commit is contained in:
parent
7175992ce4
commit
8b89bce2a8
|
@ -1,5 +1,7 @@
|
||||||
## v0.24.3 (WIP)
|
## v0.24.3 (WIP)
|
||||||
|
|
||||||
|
- Fixed incorrectly reported unique validator error for fields starting with name of another field (#6281; thanks @svobol13).
|
||||||
|
|
||||||
- Reload the created/edited records data in the RecordsPicker UI.
|
- Reload the created/edited records data in the RecordsPicker UI.
|
||||||
|
|
||||||
- Updated Go dependencies.
|
- Updated Go dependencies.
|
||||||
|
|
|
@ -50,7 +50,6 @@ func NormalizeUniqueIndexError(err error, tableOrAlias string, fieldNames []stri
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
if _, ok := err.(validation.Errors); ok {
|
if _, ok := err.(validation.Errors); ok {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -59,12 +58,14 @@ func NormalizeUniqueIndexError(err error, tableOrAlias string, fieldNames []stri
|
||||||
|
|
||||||
// check for unique constraint failure
|
// check for unique constraint failure
|
||||||
if strings.Contains(msg, "unique constraint failed") {
|
if strings.Contains(msg, "unique constraint failed") {
|
||||||
|
// note: extra space to unify multi-columns lookup
|
||||||
|
msg = strings.ReplaceAll(strings.TrimSpace(msg), ",", " ") + " "
|
||||||
|
|
||||||
normalizedErrs := validation.Errors{}
|
normalizedErrs := validation.Errors{}
|
||||||
msg = strings.ReplaceAll(strings.TrimSpace(msg), ",", " ")
|
|
||||||
|
|
||||||
for _, name := range fieldNames {
|
for _, name := range fieldNames {
|
||||||
// blank space to unify multi-columns lookup
|
// note: extra space to exclude other fields starting with the current field name
|
||||||
if strings.Contains(msg+" ", strings.ToLower(tableOrAlias+"."+name)) {
|
if strings.Contains(msg, strings.ToLower(tableOrAlias+"."+name+" ")) {
|
||||||
normalizedErrs[name] = validation.NewError("validation_not_unique", "Value must be unique")
|
normalizedErrs[name] = validation.NewError("validation_not_unique", "Value must be unique")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,13 @@ func TestNormalizeUniqueIndexError(t *testing.T) {
|
||||||
[]string{"a", "b", "c"},
|
[]string{"a", "b", "c"},
|
||||||
[]string{"a", "b"},
|
[]string{"a", "b"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"unique index error with matching table name and field starting with the name of another non-unique field",
|
||||||
|
errors.New("UNIQUE constraint failed for fields test.a_2,test.c"),
|
||||||
|
"test",
|
||||||
|
[]string{"a", "a_2", "c"},
|
||||||
|
[]string{"a_2", "c"},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
|
|
Loading…
Reference in New Issue