This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 6b74859ac fix: creating a connection with the same name will overwrite
the previous one (#4424)
6b74859ac is described below
commit 6b74859aca0f20001921a96d569e31d67f8c0555
Author: mindlesscloud <[email protected]>
AuthorDate: Wed Feb 15 16:25:05 2023 +0800
fix: creating a connection with the same name will overwrite the previous
one (#4424)
---
backend/helpers/pluginhelper/api/connection_helper.go | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/backend/helpers/pluginhelper/api/connection_helper.go
b/backend/helpers/pluginhelper/api/connection_helper.go
index da825d90c..96f3fbdb9 100644
--- a/backend/helpers/pluginhelper/api/connection_helper.go
+++ b/backend/helpers/pluginhelper/api/connection_helper.go
@@ -18,17 +18,15 @@ limitations under the License.
package api
import (
- "github.com/apache/incubator-devlake/core/models"
- "strconv"
- "strings"
-
"github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/dal"
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/log"
+ "github.com/apache/incubator-devlake/core/models"
plugin "github.com/apache/incubator-devlake/core/plugin"
"github.com/apache/incubator-devlake/helpers/pluginhelper/api/apihelperabstract"
"github.com/go-playground/validator/v10"
+ "strconv"
)
// ConnectionApiHelper is used to write the CURD of connection
@@ -62,7 +60,7 @@ func (c *ConnectionApiHelper) Create(connection interface{},
input *plugin.ApiRe
if err != nil {
return err
}
- return c.save(connection)
+ return c.save(connection, c.db.Create)
}
// Patch (Modify) a connection record based on request body
@@ -76,7 +74,7 @@ func (c *ConnectionApiHelper) Patch(connection interface{},
input *plugin.ApiRes
if err != nil {
return err
}
- return c.save(connection)
+ return c.save(connection, c.db.CreateOrUpdate)
}
// First finds connection from db by parsing request input and decrypt it
@@ -119,11 +117,11 @@ func (c *ConnectionApiHelper) merge(connection
interface{}, body map[string]inte
return Decode(body, connection, c.validator)
}
-func (c *ConnectionApiHelper) save(connection interface{}) errors.Error {
- err := CallDB(c.db.CreateOrUpdate, connection)
+func (c *ConnectionApiHelper) save(connection interface{}, method func(entity
interface{}, clauses ...dal.Clause) errors.Error) errors.Error {
+ err := CallDB(method, connection)
if err != nil {
- if strings.Contains(strings.ToLower(err.Error()), "duplicate") {
- return errors.BadInput.Wrap(err, "duplicated Connection
Name")
+ if c.db.IsDuplicationError(err) {
+ return errors.BadInput.New("the connection name already
exists")
}
return err
}