Skip to content

Conversation

@chenak-a
Copy link
Contributor

@chenak-a chenak-a commented Jul 4, 2025

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

Closes open-feature/python-sdk#516


Describe the solution you've provided

The LaunchDarkly Python SDK returns numeric flag values as Object, without distinguishing between int and float, which previously led to type mismatch errors in OpenFeature evaluations.

This PR introduces a serialize_value method to gracefully cast returned numeric values to the expected type:

  • Casts int to float when the flag type is FLOAT.
  • Casts float (when safely castable) to int when the flag type is INTEGER.
  • Ensures bool is not treated as int or float.
  • Leaves str, dict, list, and bool values untouched if matching.

This approach allows compatible numeric values to pass type validation while maintaining correctness and avoiding unnecessary failures, aligning the Python SDK behavior with LaunchDarkly’s handling in other environments.


Describe alternatives you've considered

  • Continuing strict type enforcement, rejecting all numeric mismatches (int vs. float), but this would unnecessarily reject valid use cases.
  • Handling casting logic outside of the provider, but handling it within the provider ensures correctness and consistency for all downstream consumers.

Additional context

  • Extended and parameterized test coverage to ensure values are correctly cast or rejected while maintaining type correctness.
  • This change improves developer experience while respecting OpenFeature type expectations and LaunchDarkly’s flexible numeric handling.

@chenak-a chenak-a requested a review from a team as a code owner July 4, 2025 04:40
@jsonbailey jsonbailey merged commit 7429f28 into launchdarkly:main Jul 7, 2025
11 checks passed
jsonbailey added a commit that referenced this pull request Jul 7, 2025
🤖 I have created a release *beep* *boop*
---


##
[0.4.1](0.4.0...0.4.1)
(2025-07-07)


### Bug Fixes

* gracefully cast for numeric flag evaluations
([#27](#27))
([7429f28](7429f28))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Jason Bailey <jbailey@launchdarkly.com>
@jsonbailey
Copy link
Contributor

@chenak-a Thanks for the PR. I made some minor tweaks. This has been released as v0.4.1.

@fpiche
Copy link

fpiche commented Jul 8, 2025

@jsonbailey heads up that the release pipeline is failing, seems to have failed to release 0.4.0 as well

@jsonbailey
Copy link
Contributor

@fpiche Thanks for calling that out. This has been corrected.

@chenak-a
Copy link
Contributor Author

chenak-a commented Jul 8, 2025

@chenak-a Thanks for the PR. I made some minor tweaks. This has been released as v0.4.1.

happy to contribute 🙂

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.

[Bug] OpenFeatureClient _typecheck_flag_value incorrectly raises type mismatch between int and float

4 participants