Skip to content

Conversation

@sysradium
Copy link
Contributor

@sysradium sysradium commented Sep 25, 2025

When using with flipt I observed that since it does not always return metadata key in the payload we end up having this:

 File "/private/tmp/.venv/lib/python3.13/site-packages/openfeature/contrib/provider/ofrep/__init__.py", line 155, in _resolve
    flag_metadata=data["metadata"],
                  ~~~~^^^^^^^^^^^^
KeyError: 'metadata'

I suggest just to have a fallback to a empty dict?

The test example:

from openfeature import api
from openfeature.contrib.provider.flipt import FliptProvider

api.set_provider(
    FliptProvider(namespace="default")
)
client = api.get_client()
print(client.get_boolean_value("flag-test", False))

Versions:

openfeature-provider-flipt==0.1.3
openfeature-provider-ofrep==0.1.1
openfeature-sdk==0.8.3

@sysradium sysradium requested review from a team as code owners September 25, 2025 10:28
@gemini-code-assist
Copy link

Summary of Changes

Hello @sysradium, 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 OpenFeature OFREP provider by preventing a KeyError that previously occurred when the upstream service did not include a metadata key in its response payload. By implementing a fallback to an empty dictionary for flag_metadata, the provider becomes more robust and avoids crashes in scenarios where metadata is optional or absent, ensuring smoother operation.

Highlights

  • Error Prevention: Addresses a KeyError that occurred when the metadata key was absent from the payload returned by services like Flipt.
  • Increased Robustness: Improves the OpenFeature OFREP provider's resilience by providing a default empty dictionary for flag_metadata when the key is not present.
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

@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 effectively resolves a KeyError that occurs when the metadata key is absent from the OFREP provider's response. The use of data.get("metadata", {}) is a correct and idiomatic way to handle optional dictionary keys in Python. While the fix is good, I've added a comment suggesting the addition of a unit test to cover this specific scenario, which will help prevent future regressions and ensure the provider is robust against this type of API response variation.

@sysradium sysradium changed the title return default dict if not meta provided fix: return default dict if not meta provided Sep 25, 2025
Signed-off-by: sysradium <sysradium@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Sep 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.40%. Comparing base (6ad6c0c) to head (bbbd268).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #304      +/-   ##
==========================================
- Coverage   90.73%   86.40%   -4.33%     
==========================================
  Files           6        1       -5     
  Lines         205      103     -102     
==========================================
- Hits          186       89      -97     
+ Misses         19       14       -5     

☔ View full report in Codecov by Sentry.
📢 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.

@gruebel
Copy link
Member

gruebel commented Sep 25, 2025

@sysradium change looks good. as far as I can tell it also reflects the specs to return an empty record. can you check the DCO part, it looks like you forgot to sign-off the last commit.

Signed-off-by: sysradium <sysradium@users.noreply.github.com>
@sysradium
Copy link
Contributor Author

sysradium commented Sep 25, 2025

@gruebel yeah, I did on the first commit, but forgot to do it on the last one.
Done:
image

Copy link
Member

@gruebel gruebel left a comment

Choose a reason for hiding this comment

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

thanks 🍻

@gruebel gruebel merged commit 05c99eb into open-feature:main Sep 25, 2025
13 of 14 checks passed
@sysradium sysradium deleted the metadata-hotfix branch September 25, 2025 16:23
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.

2 participants