Skip to content

Commit

Permalink
Fix panic with value conversion (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
beevital authored Jul 3, 2024
1 parent 821aec1 commit 12f4bb3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.2.1...HEAD)
## [Unreleased](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.2.2...HEAD)

## [1.2.2](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.2.1...v1.2.2)

## Fixed

Issue `panic: Can't convert value to int` on version upgrade for some connectors.

## [1.2.1](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.2.0...v1.2.1)

Expand Down
25 changes: 20 additions & 5 deletions fivetran/framework/core/model/connector_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,16 +331,22 @@ func getValueFromAttrValue(av attr.Value, fieldsMap map[string]common.ConfigFiel
if currentField != nil {
if t, ok := currentField.ItemType[service]; ok {
if t == common.Integer {
if v.ValueString() == "" {
return nil
}
res, err := strconv.Atoi(v.ValueString())
if err != nil {
panic(fmt.Sprintf("Can't convert value %v to int", v.ValueString()))
return int(0)
}
return res
}
if t == common.Float {
if v.ValueString() == "" {
return nil
}
res, err := strconv.ParseFloat(v.ValueString(), 64)
if err != nil {
panic(fmt.Sprintf("Can't convert value %v to int", v.ValueString()))
return float64(0)
}
return res
}
Expand All @@ -362,22 +368,31 @@ func getValueFromAttrValue(av attr.Value, fieldsMap map[string]common.ConfigFiel
if scf, ok := fieldsMap[an+"_"+service]; ok {
cf = scf
}
result[an] = getValueFromAttrValue(av, cf.ItemFields, &cf, service)
value := getValueFromAttrValue(av, cf.ItemFields, &cf, service)
if value != nil {
result[an] = value
}
}
}
return result
}
if v, ok := av.(basetypes.SetValue); ok {
result := make([]interface{}, 0)
for _, ev := range v.Elements() {
result = append(result, getValueFromAttrValue(ev, fieldsMap, currentField, service))
value := getValueFromAttrValue(ev, fieldsMap, currentField, service)
if value != nil {
result = append(result, value)
}
}
return result
}
if v, ok := av.(basetypes.ListValue); ok {
result := make([]interface{}, 0)
for _, ev := range v.Elements() {
result = append(result, getValueFromAttrValue(ev, fieldsMap, currentField, service))
value := getValueFromAttrValue(ev, fieldsMap, currentField, service)
if value != nil {
result = append(result, value)
}
}
return result
}
Expand Down
2 changes: 1 addition & 1 deletion fivetran/framework/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
)

const Version = "1.2.1" // Current provider version
const Version = "1.2.2" // Current provider version

type fivetranProvider struct {
mockClient httputils.HttpClient
Expand Down

0 comments on commit 12f4bb3

Please sign in to comment.