Skip to content

fix: validate cloud variables using SDK types - #125

Open
pcbeingused333 wants to merge 1 commit into
DevCycleHQ:mainfrom
pcbeingused333:fix/cloud-number-types-c3517
Open

pcbeingused333 wants to merge 1 commit into
DevCycleHQ:mainfrom
pcbeingused333:fix/cloud-number-types-c3517

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Cloud variable validation uses Python runtime classes, so an integer default rejects a floating-point Number and a float default rejects an integer Number. Since Python treats bool as a subclass of int, an integer response can also be accepted for a boolean default.

Compare the default's existing SDK type classification with the returned variable type. This accepts both numeric representations as Number and keeps Boolean separate.

Testing and validation

python -m unittest test.test_cloud_client: 20 tests pass. Before the fix, the added regression cases produce three failures: both mixed numeric directions and an integer response with a boolean default. Coverage also checks matching numeric representations and the reverse Boolean/Number mismatch.

AI assistance: this change and its tests were generated with Codex.

@pcbeingused333
pcbeingused333 requested a review from a team as a code owner November 15, 2026 21:54
@JamieSinn

Copy link
Copy Markdown
Member

I'm not sure this aligns with the other default behaviour that we have specified in the other SDKs.

Can you clarify a use case this fails in?

@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Thanks for looking. A concrete case where the current check fails: a Number variable whose value is 2 in the dashboard. The cloud API returns JSON 2, which Python parses as int. A caller doing client.variable(user, "retries", 0.0) (a float default, the usual way to pass a Number default) gets isinstance(0.0, int) == False, so the SDK logs a type-mismatch warning and returns the default 0.0 with Variable Type Mismatch, even though the variable exists and is a valid Number. The reverse also happens: value 1.5, default 0. In both cases the Number variable never reaches the caller.

The second part was that bool is a subclass of int, so a Number variable of 2 with default False was accepted as a match, which is wrong because the SDK type is Boolean.

The change compares the SDK type of the default (determine_variable_type, the same classification the SDK already uses to build default variables) with the returned variable's type, so it aligns with the other SDKs treating Number as one type. If you'd prefer to keep the strict Python-class check and only fix the bool case, I can narrow the PR to that.

@pcbeingused333

Copy link
Copy Markdown
Contributor Author

The concrete scenario covered by the regression test is a Number variable returned by bucketing as 1.5 with an application fallback of 0: the current cloud client returns 0 with Variable Type Mismatch because isinstance(0, float) is false; the reverse case, a returned 2 with fallback 0.0, also defaults. This was found through code inspection and covered with mocked bucketing responses, rather than observed in a production application. The rationale for the change was that this SDK's existing determine_variable_type helper classifies both int and float as Number, but that alone does not establish the intended contract across SDKs. Should the cloud client deliberately preserve the exact Python numeric type of the fallback, or accept both numeric representations as Number?

(Prepared with the assistance of an AI coding agent.)

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.

2 participants