fix: Report a type mismatch for non-numeric flag values - #29
Open
kinyoklion wants to merge 1 commit into
Open
Conversation
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Contributor
|
@cursor review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Numeric flag resolution now accepts only numeric flag values, and converts them to the requested type.
is_numericaccepted numeric strings, so a flag whose value is"5"was returned as a string fromresolveIntegerValue. The OpenFeature client'sgetIntegerValue(): intthen threw aTypeErrorinternally, which it swallows per spec requirement 1.4.9 and reports as error codeGENERAL— instead of theTYPE_MISMATCHthe provider should have reported.int(a float is truncated) and a float flag to afloat, rather than passing the raw JSON type through.Implementation details
Because the value is converted, the result handed to the details converter is a new
EvaluationDetailcarrying the converted value with the original variation index and reason.EvaluationDetail::isDefaultValue()is derived from the variation index, which is preserved, so the variant of the resolution details is unchanged.Found during the weekly OpenFeature provider audit.
Requirements
Related issues
None.
Describe the solution you've provided
The integer and float branches check
is_int/is_floatinstead ofis_numeric, and the accepted value is cast to the requested type. Rejected values continue through the existingmismatchedTypeDetailspath, so they reportTYPE_MISMATCHwith the default value.Describe alternatives you've considered
Keeping
is_numericand casting numeric strings as well: that hides a genuinely mistyped flag instead of reporting it, and disagrees with the other providers.Additional context
Testing:
make check(composer cs-check,composer phpstan,composer phpunit). The existing type-matching data set gains numeric-string and non-integral-float cases and now asserts withassertSame, so the resolved type is checked and not just its loose value.Link to Devin session: https://app.devin.ai/sessions/38a6eaf69fcf41109e136a1d0fe5e899
Open in Devin Desktop: https://app.devin.ai/desktop/session/38a6eaf69fcf41109e136a1d0fe5e899?variant=devin
Requested by: @kinyoklion
Note
Overview
Integer and float flag resolution no longer treats numeric strings as valid: type checks use
is_int/is_floatinstead ofis_numeric, so a flag value like"5"now returns the default withTYPE_MISMATCHinstead of a string that could surface as aGENERALerror inside the OpenFeature client.Accepted numeric values are cast to the requested type (
inttruncates floats;floatpromotes ints), and the provider passes a newEvaluationDetailwith the converted value while preserving variation index and reason.Tests add numeric-string and float-to-int cases, switch type-matching assertions to
assertSame, and covervalueForAll("5")for integer/float resolution errors.Reviewed by Cursor Bugbot for commit 0685543. Bugbot is set up for automated code reviews on this repo. Configure here.