Skip to content

fix(utils): accept json.Number in ToDecimal#22460

Open
ozpool wants to merge 1 commit into
smartcontractkit:developfrom
ozpool:fix/8504-todecimal-jsonnumber
Open

fix(utils): accept json.Number in ToDecimal#22460
ozpool wants to merge 1 commit into
smartcontractkit:developfrom
ozpool:fix/8504-todecimal-jsonnumber

Conversation

@ozpool
Copy link
Copy Markdown

@ozpool ozpool commented May 14, 2026

Problem

utils.ToDecimal is used wherever the node has to coerce a pipeline value into a decimal.Decimal: pipeline/task_params.go, pipeline/common_eth.go, ocrcommon/data_source.go, ocrcommon/telemetry.go, fluxmonitorv2/flux_monitor.go, etc.

The pipeline JSON decoder uses Decoder.UseNumber() (see core/services/pipeline/getters.go:132 and task.jsonparse.go:64), so any value coming from an HTTP JSON payload arrives downstream as json.Number, not float64. ToDecimal's type switch handled string, all int*/uint*, float32/float64, big.Int, decimal.Decimal - but not json.Number. Result: every task that pulled a numeric value out of an HTTP response and tried to turn it into a decimal blew up with:

type json.Number cannot be converted to decimal.Decimal: bad input for task

The user-visible case in #8504 is ethabiencode with a uint256[] argument, but fluxmonitor, OCR data_source, and OCR telemetry all sit on the same code path.

Fix

Add a json.Number case at the top of the type switch in ToDecimal:

case json.Number:
    return decimal.NewFromString(string(v))

json.Number is a string alias under the hood, so decimal.NewFromString parses integer and floating point forms identically and surfaces bad input as a regular parse error instead of the previous misleading type-mismatch message.

Test

core/utils/decimal_test.go is extended with three cases:

  • json.Number("123") succeeds
  • json.Number("-1.1") succeeds
  • json.Number("not-a-number") returns an error

Both successful cases fail on develop without this patch.

Fixes #8504

The pipeline parses HTTP JSON payloads with Decoder.UseNumber(), which
returns numeric values as json.Number rather than float64. ToDecimal's
type switch did not include a json.Number case, so any downstream task
that fed a HTTP-derived number into it (ethabiencode with a uint256[]
argument, fluxmonitor, OCR data_source, the OCR telemetry path)
failed with:

    type json.Number cannot be converted to decimal.Decimal

Add a case that converts via decimal.NewFromString(string(v)) so both
integer and floating point JSON numbers round-trip cleanly. Bad input
still surfaces as a parse error rather than the previous misleading
type-mismatch message.

Adds regression coverage in core/utils/decimal_test.go for the integer,
floating point, and malformed json.Number forms. The integer/float
cases fail on develop without this patch.

Fixes smartcontractkit#8504
@ozpool ozpool requested review from a team as code owners May 14, 2026 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[NODE] ETHABIEncode: type json.Number cannot be converted to decimal.Decimal

1 participant