Skip to content

Commit 05c99eb

Browse files
authored
fix: return default dict if not meta provided (#304)
* return default dict if not meta provided Signed-off-by: sysradium <sysradium@users.noreply.github.com> * add test Signed-off-by: sysradium <sysradium@users.noreply.github.com> --------- Signed-off-by: sysradium <sysradium@users.noreply.github.com>
1 parent 6ad6c0c commit 05c99eb

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

providers/openfeature-provider-ofrep/src/openfeature/contrib/provider/ofrep/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def _resolve(
168168
value=data["value"],
169169
reason=Reason[data["reason"]],
170170
variant=data["variant"],
171-
flag_metadata=data["metadata"],
171+
flag_metadata=data.get("metadata", {}),
172172
)
173173

174174
def _handle_error(self, exception: requests.RequestException) -> NoReturn:

providers/openfeature-provider-ofrep/tests/test_provider.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,28 @@ def test_provider_typecheck_flag_value(ofrep_provider, requests_mock):
166166
ofrep_provider.resolve_boolean_details("flag_key", False)
167167

168168

169+
def test_provider_missing_metadata_field(ofrep_provider, requests_mock):
170+
"""Test that provider handles missing metadata field gracefully"""
171+
requests_mock.post(
172+
"http://localhost:8080/ofrep/v1/evaluate/flags/flag_key",
173+
json={
174+
"key": "flag_key",
175+
"reason": "TARGETING_MATCH",
176+
"variant": "true",
177+
"value": True,
178+
},
179+
)
180+
181+
resolution = ofrep_provider.resolve_boolean_details("flag_key", False)
182+
183+
assert resolution == FlagResolutionDetails(
184+
value=True,
185+
reason=Reason.TARGETING_MATCH,
186+
variant="true",
187+
flag_metadata={},
188+
)
189+
190+
169191
@pytest.mark.parametrize(
170192
"base_url",
171193
[

0 commit comments

Comments
 (0)