Skip to content

Commit 12f4bb3

Browse files
authored
Fix panic with value conversion (#331)
1 parent 821aec1 commit 12f4bb3

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.2.1...HEAD)
8+
## [Unreleased](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.2.2...HEAD)
9+
10+
## [1.2.2](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.2.1...v1.2.2)
11+
12+
## Fixed
13+
14+
Issue `panic: Can't convert value to int` on version upgrade for some connectors.
915

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

fivetran/framework/core/model/connector_config.go

+20-5
Original file line numberDiff line numberDiff line change
@@ -331,16 +331,22 @@ func getValueFromAttrValue(av attr.Value, fieldsMap map[string]common.ConfigFiel
331331
if currentField != nil {
332332
if t, ok := currentField.ItemType[service]; ok {
333333
if t == common.Integer {
334+
if v.ValueString() == "" {
335+
return nil
336+
}
334337
res, err := strconv.Atoi(v.ValueString())
335338
if err != nil {
336-
panic(fmt.Sprintf("Can't convert value %v to int", v.ValueString()))
339+
return int(0)
337340
}
338341
return res
339342
}
340343
if t == common.Float {
344+
if v.ValueString() == "" {
345+
return nil
346+
}
341347
res, err := strconv.ParseFloat(v.ValueString(), 64)
342348
if err != nil {
343-
panic(fmt.Sprintf("Can't convert value %v to int", v.ValueString()))
349+
return float64(0)
344350
}
345351
return res
346352
}
@@ -362,22 +368,31 @@ func getValueFromAttrValue(av attr.Value, fieldsMap map[string]common.ConfigFiel
362368
if scf, ok := fieldsMap[an+"_"+service]; ok {
363369
cf = scf
364370
}
365-
result[an] = getValueFromAttrValue(av, cf.ItemFields, &cf, service)
371+
value := getValueFromAttrValue(av, cf.ItemFields, &cf, service)
372+
if value != nil {
373+
result[an] = value
374+
}
366375
}
367376
}
368377
return result
369378
}
370379
if v, ok := av.(basetypes.SetValue); ok {
371380
result := make([]interface{}, 0)
372381
for _, ev := range v.Elements() {
373-
result = append(result, getValueFromAttrValue(ev, fieldsMap, currentField, service))
382+
value := getValueFromAttrValue(ev, fieldsMap, currentField, service)
383+
if value != nil {
384+
result = append(result, value)
385+
}
374386
}
375387
return result
376388
}
377389
if v, ok := av.(basetypes.ListValue); ok {
378390
result := make([]interface{}, 0)
379391
for _, ev := range v.Elements() {
380-
result = append(result, getValueFromAttrValue(ev, fieldsMap, currentField, service))
392+
value := getValueFromAttrValue(ev, fieldsMap, currentField, service)
393+
if value != nil {
394+
result = append(result, value)
395+
}
381396
}
382397
return result
383398
}

fivetran/framework/provider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/hashicorp/terraform-plugin-framework/types"
1818
)
1919

20-
const Version = "1.2.1" // Current provider version
20+
const Version = "1.2.2" // Current provider version
2121

2222
type fivetranProvider struct {
2323
mockClient httputils.HttpClient

0 commit comments

Comments
 (0)