Skip to content

fix: use FloatVariable for number-type variables with integer values#36354

Open
EvanYao826 wants to merge 1 commit into
langgenius:mainfrom
EvanYao826:fix/float-var-integer-coercion
Open

fix: use FloatVariable for number-type variables with integer values#36354
EvanYao826 wants to merge 1 commit into
langgenius:mainfrom
EvanYao826:fix/float-var-integer-coercion

Conversation

@EvanYao826
Copy link
Copy Markdown
Contributor

Problem

When value_type is "number" and the value is an integer (e.g. 0), the _build_variable_from_mapping function creates an IntegerVariable and changes value_type to "integer". This causes subsequent conversation turns to fail with:

not supported value type integer

when a code node outputs a float value for the same conversation variable.

Steps to Reproduce

  1. Create a conversation variable in ChatFlow with value: 0.0 (stored as value: 0, value_type: number)
  2. Use a Code node to output a Number variable with a float value
  3. First conversation turn works
  4. Second turn fails because the variable type was narrowed from number to integer

Fix

When value_type is "number" and the value is an integer, always create a FloatVariable (converting the int value to float). This ensures the variable type stays as float across conversation turns, which is compatible with both integer and float values from code nodes.

Also added not isinstance(value, bool) guard since bool is a subclass of int in Python.

Fixes #36346

When value_type is 'number' and the value is an integer (e.g. 0), the code
was creating IntegerVariable and changing value_type to 'integer'. This
caused subsequent turns to fail with 'not supported value type integer'
when a code node outputs a float value for the same variable.

Fix: when value_type is 'number', always create FloatVariable (converting
int values to float) so the variable type stays consistent across turns.

Fixes langgenius#36346
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 18, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 0.00% 44.42% +44.42%
Strict coverage 0.00% 43.95% +43.95%
Typed symbols 0 22,535 +22,535
Untyped symbols 0 28,500 +28,500
Modules 0 2561 +2,561

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: not supported value type integer because cannot init a float var

1 participant