mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-03-30 09:22:37 +02:00
[#6281] fixed unique validator error
This commit is contained in:
parent
7175992ce4
commit
8b89bce2a8
@ -1,5 +1,7 @@
|
||||
## 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.
|
||||
|
||||
- Updated Go dependencies.
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user