Skip to content

feat: allowing null/missing default values #1511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Rahul-Baradol
Copy link
Member

This PR

  • supports missing/null default values, by returning FLAG_NOT_FOUND,
    • for flag configurations missing a defaultValue, and
    • for which targeting doesn't resolve a variant and there is no defaultValue

Related Issues

Fixes #1438

Signed-off-by: Rahul Baradol <rahul.baradol.14@gmail.com>
Copy link
Member

@guidobrei guidobrei left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, @Rahul-Baradol.
I've added some comments on things that cached my attention.

Wondreing what the Gherkin tests will reveal.

@@ -203,6 +204,12 @@ private <T> ProviderEvaluation<T> resolve(Class<T> type, String key, EvaluationC
// check variant existence
Object value = flag.getVariants().get(resolvedVariant);
if (value == null) {
if (resolvedVariant.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

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

The resolved variant will probably not be an empty string, but null. Especially, if the defaultVariant property is not set in the data source.

Copy link
Member Author

Choose a reason for hiding this comment

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

Surprisingly, the value is coming out be empty string even if the defaultVariant is not set in the config 🤔

if (resolvedVariant.isEmpty()) {
String message = String.format("no default variant found in flag with key %s", key);
log.debug(message);
throw new FlagNotFoundError(message);
Copy link
Member

Choose a reason for hiding this comment

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

Support Explicit Code Default Values in flagd Configuration will be a default code flow, not an exceptional case.
Throwing an exception can be problematic in performance critical use-cases.

Consider returning a ProviderEvaluaitonResult with proper reason an error code instead of throwing an exception.

The same holds for the debug log message. The message is surely valuable. Consider checking if debug is enabled before constructing a new message. Or use a log.debug() overload that accepts format and arguments but does not concatenate the string beforehand.

Copy link
Contributor

Choose a reason for hiding this comment

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

According to the spec, there should be no logging on hot code paths

Copy link
Member Author

Choose a reason for hiding this comment

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

Noted!

@@ -203,6 +204,12 @@ private <T> ProviderEvaluation<T> resolve(Class<T> type, String key, EvaluationC
// check variant existence
Object value = flag.getVariants().get(resolvedVariant);
if (value == null) {
if (resolvedVariant.isEmpty()) {
String message = String.format("no default variant found in flag with key %s", key);
Copy link
Member

Choose a reason for hiding this comment

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

The message could be misleading. The resolved variant could also be the result of a misconfigured targeting rule. E.g., if a targeting rule specifies an empty variant.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, actually!
Need to figure out another way to solve this.

@toddbaert
Copy link
Member

@Rahul-Baradol if it's any help, here is my JS implementation of the same thing. I'm happy to add the e2e tests here once your implementation is complete, so you can ignore that part.

@beeme1mr beeme1mr changed the title feat!: allowing null/missing default values feat: allowing null/missing default values Jul 16, 2025
@beeme1mr
Copy link
Member

FYI, I've updated the title to remove the ! since this isn't a breaking change.

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] Update in-process Evaluation To Allow undefined or null defaultValue
8 participants