Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ganigeorgiev committed Apr 14, 2023
2 parents b347c8d + ac4a961 commit aba6279
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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
32 changes: 32 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 Expand Up @@ -1747,6 +1761,24 @@ func TestRecordCrudUpdate(t *testing.T) {
`"id":{"code":"validation_in_invalid"`,
},
},
{
Name: "unique field error check",
Method: http.MethodPatch,
Url: "/api/collections/demo2/records/llvuca81nly1qls",
Body: strings.NewReader(`{
"title":"test2"
}`),
ExpectedStatus: 400,
ExpectedContent: []string{
`"data":{`,
`"title":{`,
`"code":"validation_not_unique"`,
},
ExpectedEvents: map[string]int{
"OnRecordBeforeUpdateRequest": 1,
"OnModelBeforeUpdate": 1,
},
},

// check whether if @request.data modifer fields are properly resolved
// -----------------------------------------------------------
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 aba6279

Please sign in to comment.