@@ -240,20 +240,10 @@ func (impl AttributesServiceImpl) UpdateKeyValueByOne(key string) error {
240240}
241241
242242func (impl AttributesServiceImpl ) AddDeploymentEnforcementConfig (request * AttributesDto ) (* AttributesDto , error ) {
243- model , err := impl .attributesRepository .FindByKey (ENFORCE_DEPLOYMENT_TYPE_CONFIG )
244- if err != nil && err != pg .ErrNoRows {
245- impl .logger .Errorw ("error in fetching deploymentEnforcementConfig from db" , "error" , err , "key" , request .Key )
246- return request , err
247- }
248- dbConnection := impl .attributesRepository .GetConnection ()
249- tx , terr := dbConnection .Begin ()
250- if terr != nil {
251- return request , terr
252- }
253243 newConfig := make (map [string ]map [string ]bool )
254- err = json .Unmarshal ([]byte (request .Value ), & newConfig )
255- if err != nil {
256- return request , err
244+ attributesErr : = json .Unmarshal ([]byte (request .Value ), & newConfig )
245+ if attributesErr != nil {
246+ return request , attributesErr
257247 }
258248 for environmentId , envConfig := range newConfig {
259249 AllowedDeploymentAppTypes := 0
@@ -267,8 +257,19 @@ func (impl AttributesServiceImpl) AddDeploymentEnforcementConfig(request *Attrib
267257 "at least one deployment app type should be allowed" , environmentId ))
268258 }
269259 }
260+ dbConnection := impl .attributesRepository .GetConnection ()
261+ tx , terr := dbConnection .Begin ()
262+ if terr != nil {
263+ return request , terr
264+ }
270265 // Rollback tx on error.
271266 defer tx .Rollback ()
267+
268+ model , err := impl .attributesRepository .FindByKey (ENFORCE_DEPLOYMENT_TYPE_CONFIG )
269+ if err != nil && err != pg .ErrNoRows {
270+ impl .logger .Errorw ("error in fetching deploymentEnforcementConfig from db" , "error" , err , "key" , request .Key )
271+ return request , err
272+ }
272273 if err == pg .ErrNoRows {
273274 model := & repository.Attributes {
274275 Key : ENFORCE_DEPLOYMENT_TYPE_CONFIG ,
0 commit comments