Skip to content

Added null defaultVariant handling#79

Merged
m-olko merged 4 commits into
mainfrom
null_defaultvariant
Mar 11, 2026
Merged

Added null defaultVariant handling#79
m-olko merged 4 commits into
mainfrom
null_defaultvariant

Conversation

@m-olko
Copy link
Copy Markdown
Contributor

@m-olko m-olko commented Mar 6, 2026

This PR

Adds handling for explicit code defined default, by omitting defaultValue field or setting it to null.

Changes are also fixing some issues from the linter, that due to broken check were introduced earlier.

Related Issues

Fixes #78

Notes

Implementation of: https://github.com/open-feature/flagd/blob/main/docs/architecture-decisions/support-code-default.md

How to test

gbazelisk test //providers/flagd/tests:evaluator_test

Signed-off-by: Marcin Olko <molko@google.com>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the flag evaluation mechanism to properly handle scenarios where a "defaultVariant" is either omitted or explicitly set to "null" in the flag configuration. Previously, such cases would result in an error; now, the system correctly falls back to the code-defined default value, returning "Reason::kDefault". This change aligns the flag evaluation with the OpenFeature specification's intent for default values, improving the robustness and flexibility of feature flag management.

Highlights

  • Default Variant Handling: Implemented support for explicit code-defined defaults by treating missing or "null" "defaultVariant" fields in flag configurations as a valid fallback to the provided default value.
  • Error Handling Improvement: Modified the flag resolution logic to return "Reason::kDefault" instead of "Reason::kError" when a "defaultVariant" is not found or is "null", aligning with the OpenFeature specification for default value resolution.
  • Test Coverage: Added new unit tests to cover scenarios where "defaultVariant" is missing or explicitly set to "null", ensuring the updated evaluation logic behaves as expected.
Changelog
  • providers/flagd/src/evaluator.cpp
    • Modified the JsonLogicEvaluator::ResolveAny method to check for both missing and null defaultVariant fields.
    • Changed the return behavior from an error to a default resolution when defaultVariant is not explicitly defined or is null.
  • providers/flagd/src/sync.h
    • Added a trailing comma to an enum definition for consistent formatting.
  • providers/flagd/tests/evaluator_test.cpp
    • Added three new test cases to verify the correct behavior when defaultVariant is missing or explicitly set to null.
    • Ensured that Reason::kDefault is returned and no error code is present in these new test scenarios.
Activity
  • No specific activity (comments, reviews, progress) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 correctly implements handling for missing or null defaultVariant by returning the default value. However, the implementation has a critical flaw that can cause a crash if the defaultVariant field is missing from the flag configuration. I've provided a specific code suggestion to fix this issue by using a safer method to check for the key's presence and null value. The new tests are well-written and cover the intended functionality.

Comment thread providers/flagd/src/evaluator.cpp Outdated
Signed-off-by: Marcin Olko <molko@google.com>
@m-olko
Copy link
Copy Markdown
Contributor Author

m-olko commented Mar 6, 2026

/gemini review

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 correctly implements handling for missing or null defaultVariant by returning the code-defined default value. The core logic change in evaluator.cpp is sound, and the new tests verify this behavior. I have added a couple of suggestions for the test code: one to improve correctness with floating-point comparisons and another to reduce code duplication by using parameterized tests.

Comment thread providers/flagd/tests/evaluator_test.cpp Outdated
Comment thread providers/flagd/tests/evaluator_test.cpp Outdated
Signed-off-by: Marcin Olko <molko@google.com>
@m-olko m-olko marked this pull request as ready for review March 6, 2026 15:51
@m-olko m-olko requested review from alichka06 and oxddr March 6, 2026 15:51
Signed-off-by: Marcin Olko <molko@google.com>
@m-olko m-olko merged commit 4968556 into main Mar 11, 2026
3 checks passed
@m-olko m-olko deleted the null_defaultvariant branch March 11, 2026 13:55
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.

[flagd] [FEATURE] Support Code Default Delegation by Supporting Undefined defaultValue

3 participants