Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(api): accept valid epoch-0 timestamps in localtime conversion tool (#42027)

Harsh Kashyap0b8435da7177
diff --git a/api/core/tools/builtin_tool/providers/time/tools/localtime_to_timestamp.py b/api/core/tools/builtin_tool/providers/time/tools/localtime_to_timestamp.py
index 0dfd4a03aa7..b327c15e01b 100644
--- a/api/core/tools/builtin_tool/providers/time/tools/localtime_to_timestamp.py
+++ b/api/core/tools/builtin_tool/providers/time/tools/localtime_to_timestamp.py
@@ -31,7 +31,7 @@ class LocaltimeToTimestampTool(BuiltinTool):
time_format = "%Y-%m-%d %H:%M:%S"
timestamp = self.localtime_to_timestamp(localtime, time_format, timezone) # type: ignore
- if not timestamp:
+ if timestamp is None:
yield self.create_text_message(f"Invalid localtime: {localtime}")
return
diff --git a/api/tests/unit_tests/core/tools/test_builtin_tools_extra.py b/api/tests/unit_tests/core/tools/test_builtin_tools_extra.py
index b2270592a6f..09da0178560 100644
--- a/api/tests/unit_tests/core/tools/test_builtin_tools_extra.py
+++ b/api/tests/unit_tests/core/tools/test_builtin_tools_extra.py
@@ -392,3 +392,18 @@ def test_provider_classes_and_builtin_sort(monkeypatch: pytest.MonkeyPatch):
)
sorted_providers = BuiltinToolProviderSort.sort(providers)
assert [p.name for p in sorted_providers] == ["a", "b"]
+
+
+def test_localtime_to_timestamp_tool_epoch_zero(sqlite_session: Session):
+ localtime_tool = _build_builtin_tool(LocaltimeToTimestampTool)
+ # 1970-01-01 08:00:00 in Asia/Shanghai is exactly Unix epoch 0. A valid
+ # conversion to timestamp 0 must not be reported as "Invalid localtime"
+ # just because 0 is falsy.
+ epoch_message = list(
+ localtime_tool.invoke(
+ session=sqlite_session,
+ user_id="u",
+ tool_parameters={"localtime": "1970-01-01 08:00:00", "timezone": "Asia/Shanghai"},
+ )
+ )[0].message.text
+ assert epoch_message.strip() == "0"