fix(constraint): preserve AddData integer precision during JSON round-trip - #707
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates Client.AddData to avoid integer precision loss when round-tripping referential/inventory data through JSON before writing to driver storage.
Changes:
- Replaced
encoding/jsonmarshal/unmarshal round-trip withopa/util.RoundTrip(UseNumber) to preserve numeric precision. - Removed the unused
encoding/jsonimport and addedgithub.com/open-policy-agent/opa/v1/util.
Show a summary per file
| File | Description |
|---|---|
constraint/pkg/client/client.go |
Uses OPA’s JSON round-trip helper to prevent large integer coercion to float64 during AddData processing. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
bec3d84 to
ffd640e
Compare
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5ba5f11f24
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Motivation
Client.AddDatapreviously round-tripped referential/inventory data usingencoding/jsonMarshal/Unmarshal, which decodes numbers tofloat64and can lose precision for integers > 2^53.RoundTripOnWrite, so callers must preserve numeric precision when preparing data for driver storage to avoid policy-evaluation corruption.Description
encoding/jsonMarshal/Unmarshalround-trip inClient.AddDatawith OPA'sutil.RoundTripto preserve numeric precision by decoding numbers asjson.Number(UseNumber).encoding/jsonimport and addedgithub.com/open-policy-agent/opa/v1/utilto the imports inconstraint/pkg/client/client.go.inmem.OptRoundTripOnWrite(false)performance behavior is unchanged.Testing
go test ./pkg/client -run TestClient_AddData -count=1and the test passed (ok github.com/open-policy-agent/frameworks/constraint/pkg/client).go test ./pkg/clientand observed successful completion for the modified unit test(s).Codex Task