Skip to content

fix(memprovider): return TYPE_MISMATCH for scalar object evaluations - #667

Open
kripa-sindhu-007 wants to merge 1 commit into
open-feature:mainfrom
kripa-sindhu-007:fix/memprovider-object-type-mismatch
Open

kripa-sindhu-007 wants to merge 1 commit into
open-feature:mainfrom
kripa-sindhu-007:fix/memprovider-object-type-mismatch

Conversation

@kripa-sindhu-007

Copy link
Copy Markdown
Member

InMemoryProvider.ObjectEvaluation returned any non-nil variant as an object, so a boolean, string or number came back as a valid value. Since ObjectValue returns any, the client can't catch that either. It now returns the default with TYPE_MISMATCH for scalar values, as spec 1.3.4 requires. Maps, slices, structs and pointers resolve as before, and a disabled flag still returns the caller's default.

This is a behavior change for anyone serving scalar variants through ObjectValue with memprovider or TestProvider: those calls now get the default. Two existing tests relied on that and are updated.

With this change, the spec's evaluation_v2.feature passes 73/73 locally (#665).

Closes #666

@kripa-sindhu-007
kripa-sindhu-007 requested review from a team as code owners November 27, 2026 10:44
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

ObjectEvaluation now returns the caller’s default for disabled resolutions and for scalar or nil values that do not match the object type. Tests cover accepted object-like values, type-mismatch results, and the object flag in the test provider.

Changes: Object Evaluation Type Handling

Layer / File(s) Summary
Object evaluation handling
openfeature/memprovider/in_memory_provider.go, openfeature/memprovider/in_memory_provider_test.go, openfeature/testing/testprovider_test.go
ObjectEvaluation returns the default for disabled resolutions and rejects scalar or nil values with a type-mismatch error. Tests cover maps, slices, structs, struct pointers, scalar values, nil, and the test provider’s object flag.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: sahidvelji, paddycarver, erka

Merge Risk: Minimal · up to 7cfe7

Object evaluations now reject scalar values and return the caller’s default with TYPE_MISMATCH. The fallback behavior is consistent with existing typed evaluations; the change is ready to merge subject to normal checks.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: InMemoryProvider.ObjectEvaluation now returns TYPE_MISMATCH for scalar variants. It is a conventional fix(memprovider) title that a teammate scanning history can under…
Description check Passed The description explains the behavior change. It states that scalar variants now return the default with TYPE_MISMATCH, that maps, slices, structs and pointers are unchanged, and that a disabled flag …
Linked Issues check Passed Issue #666 requires that ObjectEvaluation return the default with reason ERROR and error code TYPE_MISMATCH when the resolved value is a scalar. At head, openfeature/memprovider/in_memory_provider.go …
Out of Scope Changes check Passed The changes fall into three areas. (1) in_memory_provider.go: the ObjectEvaluation type check, the isObject helper, and the reflect import. These implement #666 directly. (2) in_memory_provider_test.g…
Full details: Title check

Explanation

The title names the main change: InMemoryProvider.ObjectEvaluation now returns TYPE_MISMATCH for scalar variants. It is a conventional fix(memprovider) title that a teammate scanning history can understand.

Full details: Description check

Explanation

The description explains the behavior change. It states that scalar variants now return the default with TYPE_MISMATCH, that maps, slices, structs and pointers are unchanged, and that a disabled flag still returns the default. It also names the updated tests and links issue #666.

Full details: Linked Issues check

Explanation

Issue #666 requires that ObjectEvaluation return the default with reason ERROR and error code TYPE_MISMATCH when the resolved value is a scalar. At head, openfeature/memprovider/in_memory_provider.go ObjectEvaluation keeps resolveFlag only when detail.Reason is DisabledReason or isObject(resolveFlag) is true. Otherwise it sets result to defaultValue, Reason to ErrorReason, and ResolutionError to NewTypeMismatchResolutionError. The new isObject helper returns false for reflect Bool, String, integer, unsigned, float, and complex kinds, and for nil. It returns true for maps, slices, structs, and pointers, which the issue asks to keep. The issue example (boolean-flag evaluated as object with default {"a": 1}) now yields the default with TYPE_MISMATCH. The PR summary reports that test changes cover map, slice, struct, and pointer acceptance and scalar and nil rejection. I did not read the test file diffs directly, so test coverage rests on the reported summary. The reported 73/73 spec result is not independently verified here. Issue #666 is a bug report, and its coding requirement is met by the source change.

Full details: Out of Scope Changes check

Explanation

The changes fall into three areas. (1) in_memory_provider.go: the ObjectEvaluation type check, the isObject helper, and the reflect import. These implement #666 directly. (2) in_memory_provider_test.go: new tests for the object success case, the disabled-flag default case, and the type-mismatch matrix. These support the #666 change. (3) testing/testprovider_test.go: the object flag fixture is changed to a map variant, and the assertion is updated. This follows from the behavior change, because scalar variants now return the default through ObjectValue. The PR description documents this behavior change and the updated tests. No unrelated functional change was identified in the reviewed summary. The reviewed diff hunks for the test files were not read directly, so this verdict relies on the PR summary for them.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 673f8537-64db-432d-ae37-ee70697f7627
Commits

Reviewing files that changed from the base of the PR and between e0f368f and 7cfe7de.

Files selected for processing: 3

  • openfeature/memprovider/in_memory_provider.go
  • openfeature/memprovider/in_memory_provider_test.go
  • openfeature/testing/testprovider_test.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.51%. Comparing base (e0f368f) to head (7cfe7de).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #667      +/-   ##
==========================================
+ Coverage   91.31%   91.51%   +0.20%     
==========================================
  Files          22       22              
  Lines        2256     2264       +8     
==========================================
+ Hits         2060     2072      +12     
+ Misses        160      157       -3     
+ Partials       36       35       -1     
Flag Coverage Δ
e2e 91.51% <100.00%> (+0.20%) ⬆️
unit 91.51% <100.00%> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@erka

erka commented Nov 27, 2026

Copy link
Copy Markdown
Member

We need to make sure that the Grafana test suite won't be affected by this change. I see this as a potentially breaking change, so it would be great to minimize its impact.

@kripa-sindhu-007

kripa-sindhu-007 commented Nov 27, 2026 •

Copy link
Copy Markdown
Member Author

@erka I checked this against Grafana. They pin go-sdk v1.17.2, so I ran every Grafana package that imports go-sdk (63 in the root module plus pkg/infra/features, Grafana main 76d6d345) against v1.17.2 with and without this change on top. 63/63 pass both ways, identical results, featuremgmt, setting and ofrep included.

That matches the code: featuremgmt picks the typed evaluation from the variant's Go type, and config values come from json.Unmarshal, so ObjectValueDetails only ever sees maps/slices, which this change still accepts.

One catch: Grafana's tests already don't compile against our current main, with or without this PR. NewInMemoryProvider now returns *InMemoryProvider, and their tests use the value type (e.g. featuremgmt/openfeature_test.go:143 type-asserts memprovider.InMemoryProvider). So the breaking change they'd hit on the next release is that one, not this PR.

@toddbaert

toddbaert commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Thanks for the Grafana check @kripa-sindhu-007. I agree with @erka that this needs care. Even if it's more compliant, it changes results for anyone serving scalar variants through ObjectValue, and that's easy to miss in a release.

On compliance: the spec defines structure as a type separate from boolean, string and number, so IMO this PR's reading is right. But the definition is loose ("such as JSON or YAML"), and 1.3.4 is a client SHOULD that says nothing about providers. As a result, SDKs disagree: Java and .NET's in-memory providers reject scalars, JS compares with the default's typeof, and Python and Ruby don't check. Maybe we should open a spec issue to tighten the wording...

@erka @kripa-sindhu-007 what are your opinions on this? What's the best path forward in terms of stability/breakage?

@kripa-sindhu-007

kripa-sindhu-007 commented Nov 28, 2026 •

Copy link
Copy Markdown
Member Author

@toddbaert Quick correction first: the NewInMemoryProvider pointer change (#539) already shipped in v1.20.0. Grafana is just pinned below it.

I'd ship this as fix!: so it shows up in the release notes, same as #539. Anyone affected gets a TYPE_MISMATCH plus their default instead of a value with the wrong type, so it fails loudly. If we'd rather not change behaviour in a minor, I can put it behind an option instead.

+1 on the spec issue, happy to open it. cc- @erka

@erka

erka commented Nov 28, 2026

Copy link
Copy Markdown
Member

I’ve opened PR #139146 to bump to 1.20 in the Grafana repo. I wonder how it will go and how Dave will react on it.

The spec improvements are always nice to have. I think someone could argue that InterfaceEvaluationDetails means the value could be of any type, but I think aligning it with other languages is the right way to go.

@kripa-sindhu-007 Please don't do fix!:. It will bump go-sdk to v2. Probably, there is a bug in release-please that it missed that in 539. It bumped it initially to v2 but the next PR changed it to minor version release. We just need to update release notes manually next time.

@kripa-sindhu-007

Copy link
Copy Markdown
Member Author

Noted @erka. I'll keep it as fix:. The behaviour change is already called out in the PR description, so it can go into the release notes from there. I'll open the spec issue for the structure type / 1.3.4 wording. Do we have anyplace to note this so it can't get missed from release notes?

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.

[BUG] memprovider: ObjectEvaluation returns non-object values instead of TYPE_MISMATCH

3 participants