Skip to content

fix: handle missing/null targeting keys in fractional evaluator - #1949

Merged
toddbaert merged 2 commits into
open-feature:mainfrom
utafrali:fix/issue-1948-bug-missing-targeting-key-handling-diffe
Apr 20, 2026
Merged

toddbaert merged 2 commits into
open-feature:mainfrom
utafrali:fix/issue-1948-bug-missing-targeting-key-handling-diffe

Conversation

@utafrali

Copy link
Copy Markdown
Contributor

Fixes #1948

The fractional evaluator wasn't handling missing or null targeting keys the same way other SDKs did. Added nil checks to return the default variant when the key is missing or null. Also added tests for the three cases: missing key, null key, and empty string.

@utafrali
utafrali requested review from a team as code owners April 16, 2026 08:24
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 16, 2026
@netlify

netlify Bot commented Apr 16, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for polite-licorice-3db33c ready!

Name Link
🔨 Latest commit 2f03138
🔍 Latest deploy log https://app.netlify.com/projects/polite-licorice-3db33c/deploys/69e6702b03b71a0008eb5d98
😎 Deploy Preview https://deploy-preview-1949--polite-licorice-3db33c.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces safety checks in the fractional evaluator to handle cases where distributions or the targeting key are missing or null. Specifically, it adds nil checks for feDistributions and the targetingKey in dataMap, ensuring the evaluator returns early instead of potentially encountering errors. Additionally, new test cases have been added to verify the behavior when the targeting key is null, missing, or empty. I have no feedback to provide.

@toddbaert

Copy link
Copy Markdown
Member

Hey @utafrali - can you do a git commit --amend --signoff? This is a legal requirement for CNCF projects. See the failing DCO action: https://github.com/open-feature/flagd/pull/1949/checks?check_run_id=71604066833

}},
flagKey: "headerColor",
context: map[string]any{
"targetingKey": "",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi, this wasn't defined in the issue yet when you opened your PR, but the suggested fix is that targetingKey = "" should be treated the same as targetingkey = nil and a non-existent targeting key and therefore result in falling back to the default. :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@utafrali

Copy link
Copy Markdown
Contributor Author

Done, pushed the fix.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Apr 16, 2026
return nil
}

if feDistributions == nil {

@leakonvalinka leakonvalinka Apr 17, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can this ever be the case?
Edit: Oh yes, I see, with your changes below.

return "", nil, nil
}
targetingKey, ok := dataMap[targetingKeyKey].(string)
if !ok {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a suggestion: You could also simply add a check here for an empty string.

@leakonvalinka leakonvalinka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I left a feedback comment, but just as a suggestion so not blocking of course!

@utafrali

Copy link
Copy Markdown
Contributor Author

Done, pushed the fix.

@toddbaert

Copy link
Copy Markdown
Member

Hey @utafrali - can you do a git commit --amend --signoff? This is a legal requirement for CNCF projects. See the failing DCO action: https://github.com/open-feature/flagd/pull/1949/checks?check_run_id=71604066833

This still need to be done for both commits. @utafrali

@utafrali

Copy link
Copy Markdown
Contributor Author

Done, pushed the fix.

@toddbaert
toddbaert force-pushed the fix/issue-1948-bug-missing-targeting-key-handling-diffe branch from 0577ad0 to 2f03138 Compare April 20, 2026 18:27
@sonarqubecloud

Copy link
Copy Markdown

@toddbaert
toddbaert merged commit 651c7bb into open-feature:main Apr 20, 2026
13 checks passed
@github-actions github-actions Bot mentioned this pull request Apr 20, 2026
toddbaert added a commit that referenced this pull request Apr 30, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>flagd: 0.15.5</summary>

##
[0.15.5](flagd/v0.15.4...flagd/v0.15.5)
(2026-04-30)


### 🐛 Bug Fixes

* handle missing/null targeting keys in fractional evaluator
([#1949](#1949))
([651c7bb](651c7bb))
* override otel service name and version
([#1956](#1956))
([ec4ff12](ec4ff12))
* update jsonlogic for and/or bug
([#1957](#1957))
([6edd6e8](6edd6e8))
* various custom operator conformance fixes
([#1950](#1950))
([670c91c](670c91c))
</details>

<details><summary>flagd-proxy: 0.9.5</summary>

##
[0.9.5](flagd-proxy/v0.9.4...flagd-proxy/v0.9.5)
(2026-04-30)


### 🧹 Chore

* resolve open dependabot security alerts
([#1954](#1954))
([c5adbb7](c5adbb7))
</details>

<details><summary>core: 0.15.5</summary>

##
[0.15.5](core/v0.15.4...core/v0.15.5)
(2026-04-30)


### 🐛 Bug Fixes

* handle missing/null targeting keys in fractional evaluator
([#1949](#1949))
([651c7bb](651c7bb))
* override otel service name and version
([#1956](#1956))
([ec4ff12](ec4ff12))
* update jsonlogic for and/or bug
([#1957](#1957))
([6edd6e8](6edd6e8))
* various custom operator conformance fixes
([#1950](#1950))
([670c91c](670c91c))


### 🧹 Chore

* resolve open dependabot security alerts
([#1954](#1954))
([c5adbb7](c5adbb7))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Signed-off-by: OpenFeature Bot <[email protected]>
Signed-off-by: Todd Baert <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Todd Baert <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] missing targeting key handling differs across SDK implementations

4 participants