Skip to content

Commit 8f2caba

Browse files
authored
fix: Finally hooks do not get called when the provider is not ready #424 (#425)
Signed-off-by: christian.lutnik <[email protected]>
1 parent 9c2ed71 commit 8f2caba

File tree

2 files changed

+34
-30
lines changed

2 files changed

+34
-30
lines changed

openfeature/client.py

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -295,37 +295,39 @@ def evaluate_flag_details( # noqa: PLR0915
295295
reversed_merged_hooks = merged_hooks[:]
296296
reversed_merged_hooks.reverse()
297297

298-
status = self.get_provider_status()
299-
if status == ProviderStatus.NOT_READY:
300-
error_hooks(
301-
flag_type,
302-
hook_context,
303-
ProviderNotReadyError(),
304-
reversed_merged_hooks,
305-
hook_hints,
306-
)
307-
return FlagEvaluationDetails(
308-
flag_key=flag_key,
309-
value=default_value,
310-
reason=Reason.ERROR,
311-
error_code=ErrorCode.PROVIDER_NOT_READY,
312-
)
313-
if status == ProviderStatus.FATAL:
314-
error_hooks(
315-
flag_type,
316-
hook_context,
317-
ProviderFatalError(),
318-
reversed_merged_hooks,
319-
hook_hints,
320-
)
321-
return FlagEvaluationDetails(
322-
flag_key=flag_key,
323-
value=default_value,
324-
reason=Reason.ERROR,
325-
error_code=ErrorCode.PROVIDER_FATAL,
326-
)
327-
328298
try:
299+
status = self.get_provider_status()
300+
if status == ProviderStatus.NOT_READY:
301+
error_hooks(
302+
flag_type,
303+
hook_context,
304+
ProviderNotReadyError(),
305+
reversed_merged_hooks,
306+
hook_hints,
307+
)
308+
flag_evaluation = FlagEvaluationDetails(
309+
flag_key=flag_key,
310+
value=default_value,
311+
reason=Reason.ERROR,
312+
error_code=ErrorCode.PROVIDER_NOT_READY,
313+
)
314+
return flag_evaluation
315+
if status == ProviderStatus.FATAL:
316+
error_hooks(
317+
flag_type,
318+
hook_context,
319+
ProviderFatalError(),
320+
reversed_merged_hooks,
321+
hook_hints,
322+
)
323+
flag_evaluation = FlagEvaluationDetails(
324+
flag_key=flag_key,
325+
value=default_value,
326+
reason=Reason.ERROR,
327+
error_code=ErrorCode.PROVIDER_FATAL,
328+
)
329+
return flag_evaluation
330+
329331
# https://github.com/open-feature/spec/blob/main/specification/sections/03-evaluation-context.md
330332
# Any resulting evaluation context from a before hook will overwrite
331333
# duplicate fields defined globally, on the client, or in the invocation.

tests/test_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ def test_should_shortcircuit_if_provider_is_not_ready(
221221
assert flag_details.reason == Reason.ERROR
222222
assert flag_details.error_code == ErrorCode.PROVIDER_NOT_READY
223223
spy_hook.error.assert_called_once()
224+
spy_hook.finally_after.assert_called_once()
224225

225226

226227
# Requirement 1.7.7
@@ -243,6 +244,7 @@ def test_should_shortcircuit_if_provider_is_in_irrecoverable_error_state(
243244
assert flag_details.reason == Reason.ERROR
244245
assert flag_details.error_code == ErrorCode.PROVIDER_FATAL
245246
spy_hook.error.assert_called_once()
247+
spy_hook.finally_after.assert_called_once()
246248

247249

248250
def test_should_run_error_hooks_if_provider_returns_resolution_with_error_code():

0 commit comments

Comments
 (0)