Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion api/.ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ ignore = [
"F821", # undefined-name
"F841", # unused-variable
"FURB113", # repeated-append
"FURB152", # math-constant
"UP007", # non-pep604-annotation
"UP032", # f-string
"B006", # mutable-argument-default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def test_create_and_export_span_converts_attribute_types(patch_core_components:
parent_span_id=None,
span_id=2,
name="span",
attributes={"num": 5, "flag": True, "pi": 3.14, "text": "value"},
attributes={"num": 5, "flag": True, "pi": float("3.14"), "text": "value"},
events=[],
links=[],
status=Status(StatusCode.OK),
Expand All @@ -502,7 +502,7 @@ def test_create_and_export_span_converts_attribute_types(patch_core_components:
(attrs,) = span.set_attributes.call_args.args
assert attrs["num"] == 5
assert attrs["flag"] is True
assert attrs["pi"] == 3.14
assert attrs["pi"] == float("3.14")
assert attrs["text"] == "value"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ def test_payload_with_number_value(self):

def test_payload_with_float_value(self):
"""Test payload with float value."""
payload = ConversationVariableUpdatePayload(value=3.14159)
assert payload.value == 3.14159
payload = ConversationVariableUpdatePayload(value=float("3.14159"))
assert payload.value == float("3.14159")

def test_payload_with_list_value(self):
"""Test payload with list value."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ def test_validate_inputs_with_default_value():
label="test_number_float",
type=VariableEntityType.NUMBER,
required=False,
default=3.14,
default=float("3.14"),
)

result = base_app_generator._validate_inputs(
variable_entity=var_number_float,
value=None,
)

assert result == 3.14
assert result == float("3.14")

# Test with number default value as string (frontend sends as string)
var_number_string = VariableEntity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ def test_convert_input_form_to_parameters_jsonschema_validation_ok(self):
jsonschema.Draft202012Validator.check_schema(schema)

# 2) Validate instances with all types
jsonschema.validate(instance={"count": 3.14, "name": "alice"}, schema=schema)
jsonschema.validate(instance={"count": float("3.14"), "name": "alice"}, schema=schema)
jsonschema.validate(
instance={"count": 2, "enabled": True, "metadata": {"key": "val"}},
schema=schema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ def test_float_values(self) -> None:
moderation = self._create_moderation("3.14")

# Float should be converted to string for matching
result = moderation.moderation_for_inputs({"pi": 3.14159})
result = moderation.moderation_for_inputs({"pi": float("3.14159")})
assert result.flagged is True

def test_negative_numbers(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion api/tests/unit_tests/core/schemas/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_primitive_types_unchanged(self) -> None:
assert resolve_dify_schema_refs(123) == 123
assert resolve_dify_schema_refs(True) is True
assert resolve_dify_schema_refs(None) is None
assert resolve_dify_schema_refs(3.14) == 3.14
assert resolve_dify_schema_refs(float("3.14")) == float("3.14")

def test_cache_functionality(self) -> None:
"""Test that caching works correctly"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ def test_numpy_ndarray_conversion(self):
assert result == [[1, 2], [3, 4]]

# Test array with float values
test_float_array = np.array([1.5, 2.7, 3.14])
test_float_array = np.array([1.5, 2.7, float("3.14")])
result = safe_json_value(test_float_array)
assert result == [1.5, 2.7, 3.14]
assert result == [1.5, 2.7, float("3.14")]

def test_dict_conversion(self):
"""Test dictionary conversion using safe_json_dict"""
test_dict = {
"string": "value",
"number": 42,
"float": 3.14,
"float": float("3.14"),
"boolean": True,
"list": [1, 2, 3],
"nested": {"key": "value"},
Expand All @@ -106,7 +106,7 @@ def test_list_conversion(self):
test_list = [
"string",
42,
3.14,
float("3.14"),
True,
[1, 2, 3],
{"key": "value"},
Expand All @@ -123,27 +123,27 @@ def test_list_conversion(self):

def test_tuple_conversion(self):
"""Test tuple conversion to list"""
test_tuple = (1, "string", 3.14)
test_tuple = (1, "string", float("3.14"))
result = safe_json_value(test_tuple)
assert isinstance(result, list)
assert result == [1, "string", 3.14]
assert result == [1, "string", float("3.14")]

def test_set_conversion(self):
"""Test set conversion to list"""
test_set = {1, "string", 3.14}
test_set = {1, "string", float("3.14")}
result = safe_json_value(test_set)
assert isinstance(result, list)
# Note: set order is not guaranteed, so we check length and content
assert len(result) == 3
assert 1 in result
assert "string" in result
assert 3.14 in result
assert float("3.14") in result

def test_basic_types_passthrough(self):
"""Test that basic types are passed through unchanged"""
assert safe_json_value("string") == "string"
assert safe_json_value(42) == 42
assert safe_json_value(3.14) == 3.14
assert safe_json_value(float("3.14")) == float("3.14")
assert safe_json_value(True) is True
assert safe_json_value(False) is False
assert safe_json_value(None) is None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def test_workflow_tool_should_handle_empty_outputs(
[
("string_var", "test string"),
("int_var", 42),
("float_var", 3.14),
("float_var", float("3.14")),
("bool_var", True),
("list_var", [1, 2, 3]),
("dict_var", {"key": "value"}),
Expand Down
8 changes: 4 additions & 4 deletions api/tests/unit_tests/core/variables/test_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ def test_all_segments_serialization(self) -> None:
NoneSegment(),
StringSegment(value="test string"),
IntegerSegment(value=42),
FloatSegment(value=3.14),
FloatSegment(value=float("3.14")),
ObjectSegment(value={"key": "value", "number": 123}),
FileSegment(value=test_file),
ArrayAnySegment(value=[1, "string", 3.14, {"key": "value"}]),
ArrayAnySegment(value=[1, "string", float("3.14"), {"key": "value"}]),
ArrayStringSegment(value=["hello", "world"]),
ArrayNumberSegment(value=[1, 2.5, 3]),
ArrayObjectSegment(value=[{"id": 1}, {"id": 2}]),
Expand Down Expand Up @@ -233,10 +233,10 @@ def test_all_variables_serialization(self) -> None:
NoneVariable(name="none_var"),
StringVariable(value="test string", name="string_var"),
IntegerVariable(value=42, name="int_var"),
FloatVariable(value=3.14, name="float_var"),
FloatVariable(value=float("3.14"), name="float_var"),
ObjectVariable(value={"key": "value", "number": 123}, name="object_var"),
FileVariable(value=test_file, name="file_var"),
ArrayAnyVariable(value=[1, "string", 3.14, {"key": "value"}], name="array_any_var"),
ArrayAnyVariable(value=[1, "string", float("3.14"), {"key": "value"}], name="array_any_var"),
ArrayStringVariable(value=["hello", "world"], name="array_string_var"),
ArrayNumberVariable(value=[1, 2.5, 3], name="array_number_var"),
ArrayObjectVariable(value=[{"id": 1}, {"id": 2}], name="array_object_var"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def get_number_cases() -> list[ValidationTestCase]:
ValidationTestCase(SegmentType.NUMBER, 42, True, "Positive integer"),
ValidationTestCase(SegmentType.NUMBER, -42, True, "Negative integer"),
ValidationTestCase(SegmentType.NUMBER, 0, True, "Zero integer"),
ValidationTestCase(SegmentType.NUMBER, 3.14, True, "Positive float"),
ValidationTestCase(SegmentType.NUMBER, -3.14, True, "Negative float"),
ValidationTestCase(SegmentType.NUMBER, float("3.14"), True, "Positive float"),
ValidationTestCase(SegmentType.NUMBER, -float("3.14"), True, "Negative float"),
ValidationTestCase(SegmentType.NUMBER, 0.0, True, "Zero float"),
ValidationTestCase(SegmentType.NUMBER, float("inf"), True, "Positive infinity"),
ValidationTestCase(SegmentType.NUMBER, float("-inf"), True, "Negative infinity"),
Expand All @@ -122,7 +122,7 @@ def get_string_cases() -> list[ValidationTestCase]:
ValidationTestCase(SegmentType.STRING, "line1\nline2", True, "Multiline string"),
# invalid values
ValidationTestCase(SegmentType.STRING, 123, False, "Integer"),
ValidationTestCase(SegmentType.STRING, 3.14, False, "Float"),
ValidationTestCase(SegmentType.STRING, float("3.14"), False, "Float"),
ValidationTestCase(SegmentType.STRING, True, False, "Boolean"),
ValidationTestCase(SegmentType.STRING, None, False, "None value"),
ValidationTestCase(SegmentType.STRING, [], False, "Empty list"),
Expand All @@ -143,7 +143,7 @@ def get_object_cases() -> list[ValidationTestCase]:
# invalid cases
ValidationTestCase(SegmentType.OBJECT, "not a dict", False, "String"),
ValidationTestCase(SegmentType.OBJECT, 123, False, "Integer"),
ValidationTestCase(SegmentType.OBJECT, 3.14, False, "Float"),
ValidationTestCase(SegmentType.OBJECT, float("3.14"), False, "Float"),
ValidationTestCase(SegmentType.OBJECT, True, False, "Boolean"),
ValidationTestCase(SegmentType.OBJECT, None, False, "None value"),
ValidationTestCase(SegmentType.OBJECT, [], False, "Empty list"),
Expand All @@ -161,7 +161,7 @@ def get_secret_cases() -> list[ValidationTestCase]:
ValidationTestCase(SegmentType.SECRET, "very_long_secret_key_with_special_chars!@#", True, "Complex secret"),
# invalid cases
ValidationTestCase(SegmentType.SECRET, 123, False, "Integer"),
ValidationTestCase(SegmentType.SECRET, 3.14, False, "Float"),
ValidationTestCase(SegmentType.SECRET, float("3.14"), False, "Float"),
ValidationTestCase(SegmentType.SECRET, True, False, "Boolean"),
ValidationTestCase(SegmentType.SECRET, None, False, "None value"),
ValidationTestCase(SegmentType.SECRET, [], False, "Empty list"),
Expand Down Expand Up @@ -254,21 +254,21 @@ def get_array_any_validation_cases() -> list[ArrayValidationTestCase]:
return [
ArrayValidationTestCase(
SegmentType.ARRAY_ANY,
[1, "string", 3.14, {"key": "value"}, True],
[1, "string", float("3.14"), {"key": "value"}, True],
ArrayValidation.NONE,
True,
"Mixed types with NONE validation",
),
ArrayValidationTestCase(
SegmentType.ARRAY_ANY,
[1, "string", 3.14, {"key": "value"}, True],
[1, "string", float("3.14"), {"key": "value"}, True],
ArrayValidation.FIRST,
True,
"Mixed types with FIRST validation",
),
ArrayValidationTestCase(
SegmentType.ARRAY_ANY,
[1, "string", 3.14, {"key": "value"}, True],
[1, "string", float("3.14"), {"key": "value"}, True],
ArrayValidation.ALL,
True,
"Mixed types with ALL validation",
Expand Down Expand Up @@ -366,7 +366,11 @@ def get_array_number_validation_cases() -> list[ArrayValidationTestCase]:
SegmentType.ARRAY_NUMBER, ["not a number", 42], ArrayValidation.FIRST, False, "First invalid"
),
ArrayValidationTestCase(
SegmentType.ARRAY_NUMBER, [3.14, 2.71, 1.41], ArrayValidation.FIRST, True, "All valid floats"
SegmentType.ARRAY_NUMBER,
[float("3.14"), float("2.71"), 1.41],
ArrayValidation.FIRST,
True,
"All valid floats",
),
# ALL strategy
ArrayValidationTestCase(
Expand Down Expand Up @@ -566,7 +570,7 @@ def test_no_truly_unsupported_segment_types_exist(self) -> None:
elif segment_type in {SegmentType.NUMBER, SegmentType.INTEGER}:
test_value = 42
elif segment_type == SegmentType.FLOAT:
test_value = 3.14
test_value = float("3.14")
elif segment_type == SegmentType.BOOLEAN:
test_value = True
elif segment_type == SegmentType.OBJECT:
Expand Down Expand Up @@ -614,7 +618,7 @@ def test_array_validation_non_list_values(self) -> None:
non_list_values = [
"not a list",
123,
3.14,
float("3.14"),
True,
None,
{"key": "value"},
Expand Down Expand Up @@ -827,7 +831,7 @@ def test_boolean_vs_integer_type_distinction(self) -> None:

# Number type should accept both integers and floats, including booleans (since bool is subclass of int)
assert SegmentType.NUMBER.is_valid(42) is True
assert SegmentType.NUMBER.is_valid(3.14) is True
assert SegmentType.NUMBER.is_valid(float("3.14")) is True
assert SegmentType.NUMBER.is_valid(True) is True # bool is subclass of int
assert SegmentType.NUMBER.is_valid(False) is True # bool is subclass of int

Expand Down
10 changes: 5 additions & 5 deletions api/tests/unit_tests/core/variables/test_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def test_frozen_variables() -> None:
with pytest.raises(ValidationError):
int_var.value = 100 # pyrefly: ignore[read-only]

float_var = FloatVariable(name="float", value=3.14)
float_var = FloatVariable(name="float", value=float("3.14"))
with pytest.raises(ValidationError):
float_var.value = 2.718 # pyrefly: ignore[read-only]
float_var.value = float("2.718") # pyrefly: ignore[read-only]

secret_var = SecretVariable(name="secret", value="secret_value")
with pytest.raises(ValidationError):
Expand All @@ -43,7 +43,7 @@ def test_variable_value_type_immutable() -> None:
with pytest.raises(ValidationError):
IntegerVariable(value_type=SegmentType.ARRAY_ANY, name=var.name, value=var.value)

var = FloatVariable(name="float", value=3.14)
var = FloatVariable(name="float", value=float("3.14"))
with pytest.raises(ValidationError):
FloatVariable(value_type=SegmentType.ARRAY_ANY, name=var.name, value=var.value)

Expand Down Expand Up @@ -80,8 +80,8 @@ def test_variable_to_object() -> None:
assert var.to_object() == "text"
var = IntegerVariable(name="integer", value=42)
assert var.to_object() == 42
var = FloatVariable(name="float", value=3.14)
assert var.to_object() == 3.14
var = FloatVariable(name="float", value=float("3.14"))
assert var.to_object() == float("3.14")
var = SecretVariable(name="secret", value="secret_value")
assert var.to_object() == "secret_value"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_all_scalar_types_ready_on_correct_payload() -> None:
DeclaredOutputConfig(name="b", type=DeclaredOutputType.BOOLEAN),
DeclaredOutputConfig(name="o", type=DeclaredOutputType.OBJECT),
]
payload = {"s": "hello", "n": 3.14, "b": True, "o": {"k": "v"}}
payload = {"s": "hello", "n": float("3.14"), "b": True, "o": {"k": "v"}}

outcome = checker.check(declared_outputs=declared, raw_output=payload, tenant_id="t-1")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ def test_check_number_integer_value(self):
def test_check_number_float_value(self):
"""Test _check_number with float value."""
node = CodeNode.__new__(CodeNode)
result = node._check_number(3.14, "test_var")
result = node._check_number(float("3.14"), "test_var")

assert result == 3.14
assert result == float("3.14")

def test_check_number_zero(self):
"""Test _check_number with zero."""
Expand All @@ -182,9 +182,9 @@ def test_check_number_negative(self):
def test_check_number_negative_float(self):
"""Test _check_number with negative float."""
node = CodeNode.__new__(CodeNode)
result = node._check_number(-3.14159, "test_var")
result = node._check_number(-float("3.14159"), "test_var")

assert result == -3.14159
assert result == -float("3.14159")


class TestCodeNodeConvertBooleanToInt:
Expand Down Expand Up @@ -218,9 +218,9 @@ def test_convert_integer_returns_same(self):

def test_convert_float_returns_same(self):
"""Test converting float returns same value."""
result = CodeNode._convert_boolean_to_int(3.14)
result = CodeNode._convert_boolean_to_int(float("3.14"))

assert result == 3.14
assert result == float("3.14")

def test_convert_zero_returns_zero(self):
"""Test converting zero returns zero."""
Expand Down
4 changes: 2 additions & 2 deletions api/tests/unit_tests/enterprise/telemetry/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,12 @@ def test_record_histogram_calls_record_on_histogram() -> None:
labels = {"tenant_id": "t1"}
with _running_exporter(_make_grpc_config()) as exporter:
exporter._histograms[EnterpriseTelemetryHistogram.WORKFLOW_DURATION] = histogram
exporter.record_histogram(EnterpriseTelemetryHistogram.WORKFLOW_DURATION, 3.14, labels)
exporter.record_histogram(EnterpriseTelemetryHistogram.WORKFLOW_DURATION, float("3.14"), labels)

metrics = reader.get_metrics_data().resource_metrics[0].scope_metrics[0].metrics
data_point = metrics[0].data.data_points[0]
assert data_point.count == 1
assert data_point.sum == 3.14
assert data_point.sum == float("3.14")
assert dict(data_point.attributes) == labels
provider.shutdown()

Expand Down
Loading
Loading