Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions constraint/pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client

import (
"context"
"encoding/json"
"fmt"
"sort"
"strings"
Expand All @@ -19,6 +18,7 @@ import (
"github.com/open-policy-agent/frameworks/constraint/pkg/handler"
"github.com/open-policy-agent/frameworks/constraint/pkg/instrumentation"
"github.com/open-policy-agent/frameworks/constraint/pkg/types"
"github.com/open-policy-agent/opa/v1/util"
admissionv1 "k8s.io/api/admission/v1"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -539,15 +539,11 @@ func (c *Client) AddData(ctx context.Context, data interface{}) (*types.Response
}
}

// Round trip data to force untyped JSON, as drivers are not type-aware
bytes, err := json.Marshal(processedData)
if err != nil {
errMap[name] = err

continue
}
var processedDataCpy interface{}
err = json.Unmarshal(bytes, &processedDataCpy)
// Round trip data to force untyped JSON, as drivers are not type-aware.
// Use OPA's JSON decoder to preserve numeric precision by decoding numbers
// as json.Number instead of float64.
var processedDataCpy interface{} = processedData
err = util.RoundTrip(&processedDataCpy)
Comment on lines +542 to +546

Copilot AI Apr 9, 2026

Copy link

Choose a reason for hiding this comment

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

The AddData round-trip behavior change is intended to preserve integer precision (>2^53) but there is no unit test here exercising a payload with a large integer and asserting it is not coerced to float64. Adding a focused test case (e.g., data containing an int64 just above 2^53) would prevent regressions and validate the motivation for using util.RoundTrip/UseNumber.

Copilot uses AI. Check for mistakes.
if err != nil {
errMap[name] = err

Expand Down
Loading