Skip to content

Templates: keep large numeric params parseable - #32528

Merged
andig merged 1 commit into
evcc-io:masterfrom
DennisKlipp:templates-large-numbers
Aug 4, 2026
Merged

Templates: keep large numeric params parseable#32528
andig merged 1 commit into
evcc-io:masterfrom
DennisKlipp:templates-large-numbers

Conversation

@DennisKlipp

Copy link
Copy Markdown
Contributor

A required int template param with a large value is rejected as missing.

JSON numbers reach the config API as float64. RenderResult formats them with
%v, which switches to exponential notation above roughly a million, so
3493601102 becomes 3.493601102e+09. IsZero parses that as 0 and the
required check fails:

float64(3)           -> "3"                -> ToInt64 = 3
float64(8899)        -> "8899"             -> ToInt64 = 8899
float64(3493601102)  -> "3.493601102e+09"  -> ToInt64 = 0

Smaller values like a port or a phase count are unaffected, which is probably
why this went unnoticed. I ran into it with a ten digit device serial as a
template param.

Formats floats with strconv.FormatFloat(v, 'f', -1, 64) instead and handles
float in the Defaults switch. Two tests cover the formatting and the
end-to-end required check:

tmpl := &Template{Params: []Param{{Name: "serial", Type: TypeInt, Required: true}}}
_, _, err := tmpl.RenderResult(RenderModeUnitTest, map[string]any{
	"serial": float64(3493601102),
})
// before: missing required `serial`

JSON numbers reach the config API as float64. Rendering them with %v switches
to exponential notation above roughly a million, so 3493601102 became
3.493601102e+09, which no longer parses as an integer. A required int param
with such a value was rejected as missing.

Smaller values like a port or a phase count were unaffected, which is why
this went unnoticed.
@github-actions github-actions Bot added the bug Something isn't working label Aug 4, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@andig
andig enabled auto-merge (squash) August 4, 2026 18:29
@andig
andig merged commit dbae128 into evcc-io:master Aug 4, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants