diff --git a/store/sqlstore/plugin_store.go b/store/sqlstore/plugin_store.go index defd2276e4..3a003e499b 100644 --- a/store/sqlstore/plugin_store.go +++ b/store/sqlstore/plugin_store.go @@ -63,7 +63,7 @@ func (ps SqlPluginStore) SaveOrUpdate(kv *model.PluginKeyValue) (*model.PluginKe // If the error is from unique constraints violation, it's the result of a // valid race and we can report success. Otherwise we have a real error and // need to return it - if !IsUniqueConstraintError(err, []string{"PRIMARY", "PluginId", "Key", "PKey"}) { + if !IsUniqueConstraintError(err, []string{"PRIMARY", "PluginId", "Key", "PKey", "pkey"}) { return nil, model.NewAppError("SqlPluginStore.SaveOrUpdate", "store.sql_plugin_store.save.app_error", nil, err.Error(), http.StatusInternalServerError) } } @@ -93,7 +93,7 @@ func (ps SqlPluginStore) CompareAndSet(kv *model.PluginKeyValue, oldValue []byte // If the error is from unique constraints violation, it's the result of a // race condition, return false and no error. Otherwise we have a real error and // need to return it. - if IsUniqueConstraintError(err, []string{"PRIMARY", "PluginId", "Key", "PKey"}) { + if IsUniqueConstraintError(err, []string{"PRIMARY", "PluginId", "Key", "PKey", "pkey"}) { return false, nil } else { return false, model.NewAppError("SqlPluginStore.CompareAndSet", "store.sql_plugin_store.save.app_error", nil, err.Error(), http.StatusInternalServerError) diff --git a/store/storetest/plugin_store.go b/store/storetest/plugin_store.go index 3dcb0b5018..b9803994fc 100644 --- a/store/storetest/plugin_store.go +++ b/store/storetest/plugin_store.go @@ -39,6 +39,22 @@ func testPluginCompareAndSet(t *testing.T, ss store.Store) { assert.True(t, ok) }) + t.Run("set existing key without old value should fail without error because is a automatically handled race condition", func(t *testing.T) { + _, err := ss.Plugin().SaveOrUpdate(kv) + require.Nil(t, err) + + kvNew := &model.PluginKeyValue{ + PluginId: kv.PluginId, + Key: kv.Key, + Value: []byte(model.NewId()), + ExpireAt: 0, + } + + ok, err := ss.Plugin().CompareAndSet(kvNew, nil) + require.Nil(t, err) + assert.False(t, ok) + }) + t.Run("set existing key with new value should succeed given same old value", func(t *testing.T) { _, err := ss.Plugin().SaveOrUpdate(kv) require.Nil(t, err)