You've already forked pocketbase
mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-09-16 09:36:20 +02:00
synced with master
This commit is contained in:
@@ -50,7 +50,6 @@ func NormalizeUniqueIndexError(err error, tableOrAlias string, fieldNames []stri
|
||||
return err
|
||||
}
|
||||
|
||||
//
|
||||
if _, ok := err.(validation.Errors); ok {
|
||||
return err
|
||||
}
|
||||
@@ -59,12 +58,14 @@ func NormalizeUniqueIndexError(err error, tableOrAlias string, fieldNames []stri
|
||||
|
||||
// check for unique constraint failure
|
||||
if strings.Contains(msg, "unique constraint failed") {
|
||||
// note: extra space to unify multi-columns lookup
|
||||
msg = strings.ReplaceAll(strings.TrimSpace(msg), ",", " ") + " "
|
||||
|
||||
normalizedErrs := validation.Errors{}
|
||||
msg = strings.ReplaceAll(strings.TrimSpace(msg), ",", " ")
|
||||
|
||||
for _, name := range fieldNames {
|
||||
// blank space to unify multi-columns lookup
|
||||
if strings.Contains(msg+" ", strings.ToLower(tableOrAlias+"."+name)) {
|
||||
// note: extra space to exclude other fields starting with the current field name
|
||||
if strings.Contains(msg, strings.ToLower(tableOrAlias+"."+name+" ")) {
|
||||
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"},
|
||||
},
|
||||
{
|
||||
"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 {
|
||||
|
Reference in New Issue
Block a user