diff --git a/integration/update_compat_test.go b/integration/update_compat_test.go index 3839d3f5725d..2acd6f731d90 100644 --- a/integration/update_compat_test.go +++ b/integration/update_compat_test.go @@ -42,8 +42,7 @@ type updateCompatTestCase struct { resultType compatTestCaseResultType // defaults to nonEmptyResult providers []shareddata.Provider // defaults to shareddata.AllProviders() - skip string // skips test if non-empty - skipForSQLite string // optional, if set, the case is skipped for SQLite due to given issue + skip string // skips test if non-empty } // testUpdateCompat tests update compatibility test cases. @@ -59,10 +58,6 @@ func testUpdateCompat(t *testing.T, testCases map[string]updateCompatTestCase) { t.Skip(tc.skip) } - if tc.skipForSQLite != "" { - t.Skip(tc.skipForSQLite) - } - t.Parallel() providers := shareddata.AllProviders() @@ -554,18 +549,16 @@ func TestUpdateCompat(t *testing.T) { replace: bson.D{}, }, "ReplaceNonExistentUpsert": { - filter: bson.D{{"non-existent", "no-match"}}, - replace: bson.D{{"_id", "new"}}, - replaceOpts: options.Replace().SetUpsert(true), - resultType: emptyResult, - skipForSQLite: "https://github.com/FerretDB/FerretDB/issues/3183", + filter: bson.D{{"non-existent", "no-match"}}, + replace: bson.D{{"_id", "new"}}, + replaceOpts: options.Replace().SetUpsert(true), + resultType: emptyResult, }, "UpdateNonExistentUpsert": { - filter: bson.D{{"_id", "non-existent"}}, - update: bson.D{{"$set", bson.D{{"v", int32(42)}}}}, - updateOpts: options.Update().SetUpsert(true), - resultType: emptyResult, - skipForSQLite: "https://github.com/FerretDB/FerretDB/issues/3183", + filter: bson.D{{"_id", "non-existent"}}, + update: bson.D{{"$set", bson.D{{"v", int32(42)}}}}, + updateOpts: options.Update().SetUpsert(true), + resultType: emptyResult, }, } diff --git a/internal/handlers/sqlite/msg_update.go b/internal/handlers/sqlite/msg_update.go index baa23e58c4e1..2ea27e5fd189 100644 --- a/internal/handlers/sqlite/msg_update.go +++ b/internal/handlers/sqlite/msg_update.go @@ -44,15 +44,32 @@ func (h *Handler) MsgUpdate(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, // TODO https://github.com/FerretDB/FerretDB/issues/2612 _ = params.Ordered + var we *writeError + matched, modified, upserted, err := h.updateDocument(ctx, params) if err != nil { - return nil, lazyerrors.Error(err) + switch { + case backends.ErrorCodeIs(err, backends.ErrorCodeInsertDuplicateID): + // TODO https://github.com/FerretDB/FerretDB/issues/3263 + we = &writeError{ + index: int32(0), + code: commonerrors.ErrDuplicateKeyInsert, + errmsg: fmt.Sprintf(`E11000 duplicate key error collection: %s.%s`, params.DB, params.Collection), + } + + default: + return nil, lazyerrors.Error(err) + } } res := must.NotFail(types.NewDocument( "n", matched, )) + if we != nil { + res.Set("writeErrors", must.NotFail(types.NewArray(we.Document()))) + } + if upserted.Len() != 0 { res.Set("upserted", upserted) }