Skip to content

Commit 40b7a83

Browse files
committed
review comments
1 parent 9a0d46d commit 40b7a83

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

internal/sql/repository/deploymentConfig/repository.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ func (impl *RepositoryImpl) UpdateAll(tx *pg.Tx, configs []*DeploymentConfig) ([
124124
func (impl *RepositoryImpl) GetByAppIdAndEnvId(tx *pg.Tx, appId, envId int) (*DeploymentConfig, error) {
125125
result := &DeploymentConfig{}
126126
var connection orm.DB
127-
connection = tx
128-
if tx == nil {
127+
if tx != nil {
128+
connection = tx
129+
} else {
129130
connection = impl.dbConnection
130131
}
131132
err := connection.Model(result).
@@ -146,8 +147,9 @@ func (impl *RepositoryImpl) GetByAppIdAndEnvId(tx *pg.Tx, appId, envId int) (*De
146147
func (impl *RepositoryImpl) GetAppLevelConfigForDevtronApps(tx *pg.Tx, appId int) (*DeploymentConfig, error) {
147148
result := &DeploymentConfig{}
148149
var connection orm.DB
149-
connection = tx
150-
if tx == nil {
150+
if tx != nil {
151+
connection = tx
152+
} else {
151153
connection = impl.dbConnection
152154
}
153155
err := connection.Model(result).

pkg/chart/ChartService.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,12 +965,17 @@ func (impl *ChartServiceImpl) ConfigureGitOpsRepoUrlForApp(appId int, repoUrl, c
965965
if err != nil {
966966
return nil, err
967967
}
968+
committed := false
968969
tx, err := impl.chartRepository.StartTx()
969970
if err != nil {
970971
impl.logger.Errorw("error in starting transaction to update charts", "error", err)
971972
return nil, err
972973
}
973-
defer impl.chartRepository.RollbackTx(tx)
974+
defer func() {
975+
if !committed {
976+
impl.chartRepository.RollbackTx(tx)
977+
}
978+
}()
974979
var updatedCharts []*chartRepoRepository.Chart
975980
for _, ch := range charts {
976981
if !ch.IsCustomGitRepository {
@@ -1003,6 +1008,7 @@ func (impl *ChartServiceImpl) ConfigureGitOpsRepoUrlForApp(appId int, repoUrl, c
10031008
impl.logger.Errorw("error in committing transaction to update charts", "error", err)
10041009
return nil, err
10051010
}
1011+
committed = true
10061012

10071013
return deploymentConfig, nil
10081014
}

pkg/pipeline/CiCdPipelineOrchestrator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ func (impl CiCdPipelineOrchestratorImpl) DeleteApp(appId int, userId int32) erro
13701370
// Rollback tx on error.
13711371
defer tx.Rollback()
13721372
// deleting deployment config first as it is dependent on app
1373-
appDeploymentConfig, err := impl.deploymentConfigService.GetAndMigrateConfigIfAbsentForDevtronApps(nil, appId, 0)
1373+
appDeploymentConfig, err := impl.deploymentConfigService.GetAndMigrateConfigIfAbsentForDevtronApps(tx, appId, 0)
13741374
if err != nil && !errors.Is(err, pg.ErrNoRows) {
13751375
impl.logger.Errorw("error in fetching environment deployment config by appId and envId", "appId", appId, "err", err)
13761376
return err

0 commit comments

Comments
 (0)