Skip to content

Commit 3a48713

Browse files
fix: Log a non-string kind attribute as an error (#76)
**Requirements** - [x] I have added test coverage for new or changed functionality - [x] I have followed the repository's [pull request submission guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests) - [x] I have validated my changes against all supported platform versions **Related issues** OpenFeature provider spec (`OFP`) Requirement 2.1.4.1 in `launchdarkly/sdk-specs`. **Describe the solution you've provided** When an `EvaluationContext` has a `kind` attribute that is not a string, the provider ignores it and builds a `user` context. OFP 2.1.4.1 says the provider **MUST** log an error in that case, and the README already says "An error message will be logged". The converter logged it as a warning, so this changes `logger.warning` to `logger.error` and the provider test now asserts the log level. **Describe alternatives you've considered** None. **Additional context** The conversion behavior is unchanged; only the log level is different. Found during the weekly OpenFeature provider audit. Link to Devin session: https://app.devin.ai/sessions/f7bc946afe8c41a28cf7f3f497fc8b9d Open in Devin Desktop: https://app.devin.ai/desktop/session/f7bc946afe8c41a28cf7f3f497fc8b9d?variant=devin [SDK-3496](https://launchdarkly.atlassian.net/browse/SDK-3496) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Aligns logging with **OpenFeature provider spec 2.1.4.1** and the README: when `EvaluationContext` has a non-string `kind`, the converter still discards it and builds a **user** context, but now emits **`logger.error`** instead of **`logger.warning`**. > > The provider integration test **`test_logger_changes_should_cascade_to_evaluation_converter`** now asserts the captured log record is at **ERROR** level (message unchanged). > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 42c82b8. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> [SDK-3496]: https://launchdarkly.atlassian.net/browse/SDK-3496?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent d4dcdb3 commit 3a48713

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

‎ld_openfeature/impl/context_converter.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def to_ld_context(self, context: EvaluationContext) -> Context:
5252
return self.__build_multi_context(context)
5353

5454
if kind is not None and not isinstance(kind, str):
55-
logger.warning("'kind' was set to a non-string value; defaulting to user")
55+
logger.error("'kind' was set to a non-string value; defaulting to user")
5656
kind = 'user'
5757

5858
targeting_key = context.targeting_key

‎tests/test_provider.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ def test_logger_changes_should_cascade_to_evaluation_converter(provider: LaunchD
237237

238238
assert len(caplog.records) == 1
239239
assert caplog.records[0].message == "'kind' was set to a non-string value; defaulting to user"
240+
assert caplog.records[0].levelname == 'ERROR'
240241

241242

242243
def test_track_without_context_does_not_send_an_event(provider: LaunchDarklyProvider):

0 commit comments

Comments
 (0)