Skip to content

Commit

Permalink
[pocketbase#2287] fixed unique field detailed error not being returne…
Browse files Browse the repository at this point in the history
…d on DrySubmit failure
  • Loading branch information
ganigeorgiev committed Apr 13, 2023
1 parent 35e433f commit 8317ae2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Added checks for `nil` hooks in `forms.RecordUpsert` when used with custom `Dao` ([#2277](https://github.com/pocketbase/pocketbase/issues/2277)).

- Fixed unique detailed field error not returned on record create failure ([#2287](https://github.com/pocketbase/pocketbase/discussions/2287)).


## v0.14.4

Expand Down
14 changes: 14 additions & 0 deletions apis/record_crud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,20 @@ func TestRecordCrudCreate(t *testing.T) {
"OnModelAfterCreate": 1,
},
},
{
Name: "unique field error check",
Method: http.MethodPost,
Url: "/api/collections/demo2/records",
Body: strings.NewReader(`{
"title":"test2"
}`),
ExpectedStatus: 400,
ExpectedContent: []string{
`"data":{`,
`"title":{`,
`"code":"validation_not_unique"`,
},
},

// ID checks
// -----------------------------------------------------------
Expand Down
8 changes: 2 additions & 6 deletions forms/record_upsert.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ func (form *RecordUpsert) DrySubmit(callback func(txDao *daos.Dao) error) error
defer tx.Rollback()

if err := txDao.SaveRecord(form.record); err != nil {
return err
return form.prepareError(err)
}

// restore record isNew state
Expand Down Expand Up @@ -779,11 +779,7 @@ func (form *RecordUpsert) Submit(interceptors ...InterceptorFunc[*models.Record]

// persist the record model
if err := dao.SaveRecord(form.record); err != nil {
preparedErr := form.prepareError(err)
if _, ok := preparedErr.(validation.Errors); ok {
return preparedErr
}
return fmt.Errorf("failed to save the record: %w", err)
return form.prepareError(err)
}

// delete old files (if any)
Expand Down

0 comments on commit 8317ae2

Please sign in to comment.