Skip to content

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

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

fix: handle missing/null targeting keys in fractional evaluator#1949
toddbaert merged 2 commits intoopen-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
Copy link
Copy Markdown

netlify Bot commented Apr 16, 2026

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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

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 {
Copy link
Copy Markdown
Member

@leakonvalinka leakonvalinka Apr 17, 2026

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.

Copy link
Copy Markdown
Member

@leakonvalinka leakonvalinka left a comment

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
14 of 17 checks passed
@github-actions github-actions Bot mentioned this pull request Apr 20, 2026
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