Skip to content

fix: Keep booleans and numbers distinct in the in operator#433

Merged
keelerm84 merged 1 commit into
mainfrom
mk/SDK-2474/in-equality
Jun 8, 2026
Merged

fix: Keep booleans and numbers distinct in the in operator#433
keelerm84 merged 1 commit into
mainfrom
mk/SDK-2474/in-equality

Conversation

@keelerm84

@keelerm84 keelerm84 commented Jun 8, 2026

Copy link
Copy Markdown
Member

Summary

The in clause operator incorrectly matched boolean context values against numeric clause values (and vice versa). Python's bool is a subclass of int, so True == 1 and False == 0 evaluate as true, and _in used a raw context_value == clause_value. As a result:

  • A rule checking tier in [1] incorrectly matched a context where tier is True.
  • A rule checking beta in [true] incorrectly matched a context where beta is 1.

The in operator now rejects a match when exactly one side is a bool, keeping boolean and numeric JSON values distinct while still matching True == True and False == False. This mirrors the bool-exclusion idea already used by is_number in value_parsing.py.

This is a Python-specific defect. The Ruby SDK (true == 1 is false) and js-core (true === 1 is false via strict equality) are unaffected.

Fixes #432


Note

Medium Risk
Changes core flag targeting semantics for in clauses; rules that accidentally relied on bool/number equality will behave differently, but the fix aligns with JSON types and other SDKs.

Overview
Fixes incorrect flag rule matches in the Python SDK where in treated booleans and numbers as equal because True == 1 and False == 0.

_in now returns false when exactly one of the context and clause values is a bool, so JSON booleans and numbers stay distinct while same-type equality still works. Parametrized tests cover bool/bool matches and bool vs int/float non-matches.

Reviewed by Cursor Bugbot for commit ea94700. Bugbot is set up for automated code reviews on this repo. Configure here.

Python's bool is a subclass of int, so True == 1 and False == 0. This
caused the in clause operator to match boolean context values against
numeric clause values (and vice versa), e.g. a context where tier is
True incorrectly matched a rule checking tier in [1].

The in operator now rejects a match when exactly one side is a bool,
keeping boolean and numeric JSON values distinct while still matching
True == True and False == False.
@keelerm84 keelerm84 marked this pull request as ready for review June 8, 2026 13:57
@keelerm84 keelerm84 requested a review from a team as a code owner June 8, 2026 13:57
@keelerm84 keelerm84 merged commit da595ab into main Jun 8, 2026
25 of 27 checks passed
@keelerm84 keelerm84 deleted the mk/SDK-2474/in-equality branch June 8, 2026 14:20
keelerm84 pushed a commit that referenced this pull request Jun 8, 2026
🤖 I have created a release *beep* *boop*
---


##
[9.16.0](9.15.1...9.16.0)
(2026-06-08)


### Features

* Drop persistent-store cache after FDv2 in-memory store init
([#426](#426))
([563b87a](563b87a))


### Bug Fixes

* align FDv2 goodbye event with spec (reason-only)
([#422](#422))
([84b442d](84b442d))
* honor server-directed FDv1 Fallback Directive in initializer phase
([#423](#423))
([7c49bc0](7c49bc0))
* Keep booleans and numbers distinct in the in operator
([#433](#433))
([da595ab](da595ab))
* Replace Python 2-style ABC patterns with Python 3 equivalents
([22b8fe5](22b8fe5))

---
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>
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.

in operator treats boolean and numeric context attributes as equal (true matches 1)

2 participants