fix: reject boolean values for integer flags - #621
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughThe client now rejects booleans for integer flags and returns the caller’s default value for asynchronous type mismatches. Tests cover matching and mismatched values across synchronous and asynchronous getters. ChangesFlag type validation
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change correctly rejects boolean values for integer flags and returns the configured default for synchronous and asynchronous mismatches; no actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Comment |
Exclude bool from integer flag type checks while preserving other integer subclasses. Return the caller default when the async client detects a type mismatch, matching the sync path. Cover sync and async value/details getters, exact fallback types, hook behavior, and valid flag values with regression tests for open-feature#619. Signed-off-by: Hexecu <vaingloryhex@gmail.com>
e530620 to
71fe148
Compare
Document the boolean/integer distinction, async type-mismatch fallback, and the regression cases. Keep the evaluation logic and test assertions unchanged. Signed-off-by: Hexecu <vaingloryhex@gmail.com>
10f26c1 to
1e2e89d
Compare
gruebel
left a comment
There was a problem hiding this comment.
thanks for the PR, i added a few comments, nothing critical
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #621 +/- ##
==========================================
+ Coverage 98.36% 98.40% +0.03%
==========================================
Files 45 45
Lines 2514 2574 +60
==========================================
+ Hits 2473 2533 +60
Misses 41 41
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks for the review! Removed the added docstrings and moved the bool/int explanation next to the condition. Re-ran the full test suite and Gherkin tests on Python 3.10–3.14; all pass. |
This PR
I reproduced the behavior reported by @aepfli in #619: requesting a boolean flag through
get_integer_detailsreturns the boolean as a successful evaluation, instead of returning the integer default withTYPE_MISMATCH.The caller gets neither the expected type nor an indication that the flag is misconfigured for that request. The fallback is silently bypassed because Python considers
boola subclass ofint, soisinstance(True, int)passes the client's type check.Reproducing the problem
This example uses the built-in provider; no flag server or credentials are needed. Run it with
uv run --frozen python repro.pyafter saving it asrepro.pyin the checkout:On the base commit,
371aca1:With this patch, the same example returns the supplied default and reports the mismatch:
I also checked
Falsewith a default of0. The type matters here: a test that only checks equality would pass even before the fix, sinceTrue == 1andFalse == 0.Why there are two changes
The shared type check now excludes booleans when the requested type is INTEGER. I kept
isinstancefor everything else so this doesn't also reject valid integer subclasses or change how other flag types are handled.That change alone wasn't enough for the async API. While checking it, I found that the async type-mismatch branch still constructed its result with
resolution.value. It reported an error, but returned the rejected value anyway. The second change usesdefault_valuein that branch, matching the sync behavior.This also corrects the async fallback for other client-detected type mismatches, which is why the tests cover more than bool-to-int. It doesn't change provider implementations or introduce type coercion. Boolean flags and objects containing booleans continue to work as before.
Related Issues
Fixes #619. Thanks @aepfli for the reproduction and the conformance test that caught this.
How to test
The added tests exercise both value and details getters through the real
InMemoryProvider. They check the exact return type as well as the value, error details and hook behavior: a mismatch must run the error hook, skip the after hook, and give the finally hook the fallback value. There are also passing cases for valid flag values and an integer subclass, to check that the stricter bool handling doesn't affect them.To run just these tests:
uv run --frozen pytest tests/test_client.py -q \ -k 'client_returns_default_on_type_mismatch or client_preserves_matching_flag_types or typecheck_flag_value_accepts_integer_subclasses'I ran the same 39 cases against the unmodified base and this patch. Before the fix, 11 failed and 28 passed: the failures were the two sync bool-to-int cases and the nine async mismatch cases. After the fix, all 39 passed.
The full suite passed on Python 3.10 through 3.14, with 211 tests on each version. The repository's Gherkin suite also passed on each version: 21 scenarios / 84 steps, using its pinned spec and in-memory provider. Ruff, mypy, the remaining pre-commit hooks, and the wheel/sdist build passed locally as well.
Notes
For a check independent of the tests added here, I ran the in-memory self-test from python-sdk-contrib#409, at
d6de5dc, against both SDK versions. The case marked as a known failure for #619 becomesXPASS(strict)with this patch. Running that unchanged test file with--runxfail, so the assertions run normally, gives 24 passed and 5 skipped. The skips are unsupported provider capabilities; the strict marker will need updating when that suite adopts the fixed SDK.All results above are local macOS runs. I haven't tested against live flagd/OFREP servers, and these results don't replace hosted CI.