diff --git a/openfeature/providers/python-provider/gofeatureflag_python_provider/data_collector_hook.py b/openfeature/providers/python-provider/gofeatureflag_python_provider/data_collector_hook.py index fe05cfec973..687b1b87e10 100644 --- a/openfeature/providers/python-provider/gofeatureflag_python_provider/data_collector_hook.py +++ b/openfeature/providers/python-provider/gofeatureflag_python_provider/data_collector_hook.py @@ -63,8 +63,8 @@ def after( self._event_queue.append(feature_event) def error(self, hook_context: HookContext, exception: Exception, hints: dict): - if self._options.disable_data_collection or details.reason != Reason.CACHED: - # we don't collect data if the data collection is disabled or if the flag is not cached + if self._options.disable_data_collection: + # we don't collect data if the data collection is disabled return feature_event = FeatureEvent( diff --git a/openfeature/providers/python-provider/tests/test_gofeatureflag_python_provider.py b/openfeature/providers/python-provider/tests/test_gofeatureflag_python_provider.py index d756ae77a47..3bf63693265 100644 --- a/openfeature/providers/python-provider/tests/test_gofeatureflag_python_provider.py +++ b/openfeature/providers/python-provider/tests/test_gofeatureflag_python_provider.py @@ -10,6 +10,7 @@ from openfeature.exception import ErrorCode from openfeature.flag_evaluation import Reason, FlagEvaluationDetails +from gofeatureflag_python_provider.data_collector_hook import DataCollectorHook from gofeatureflag_python_provider.options import GoFeatureFlagOptions from gofeatureflag_python_provider.provider import GoFeatureFlagProvider @@ -588,6 +589,27 @@ def test_should_not_call_data_collector_if_not_having_cache(mock_request: Mock): assert mock_request.call_count == 1 +def test_hook_error(): + def _create_hook_context(): + ctx = Mock() + eval_ctx = Mock() + eval_ctx.attributes = {"anonymous": True} + eval_ctx.targeting_key = "test_user_key" + ctx.evaluation_context = eval_ctx + ctx.flag_key = "test_key" + return ctx + + hook = DataCollectorHook( + options=GoFeatureFlagOptions(endpoint="http://test.com"), http_client=Mock() + ) + hook.error( + hook_context=_create_hook_context(), + exception=Exception("test exception raised"), + hints={}, + ) + assert len(hook._event_queue) == 1 + + def _read_mock_file(flag_key: str) -> str: # This hacky if is here to make test run inside pycharm and from the root of the project if os.getcwd().endswith("/tests"):