Skip to content

fix(api): unify conversation and message timestamp defaults#38581

Open
Zhengcy05 wants to merge 1 commit into
langgenius:mainfrom
Zhengcy05:fix/conversation-message-timestamp-timezone
Open

fix(api): unify conversation and message timestamp defaults#38581
Zhengcy05 wants to merge 1 commit into
langgenius:mainfrom
Zhengcy05:fix/conversation-message-timestamp-timezone

Conversation

@Zhengcy05

Copy link
Copy Markdown

PR body:

Important

  1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md)
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

Fixes #38553.

This PR fixes a timezone inconsistency in Conversation and Message timestamps on MySQL.

Previously, created_at could be written by DB-side CURRENT_TIMESTAMP(), while several update paths explicitly assigned updated_at = naive_utc_now(). Because MySQL DATETIME does not store timezone information, that mixed DB-local creation timestamps with application-side UTC update timestamps and could produce an 8-hour discrepancy on non-UTC MySQL servers.

This change unifies the timestamp contract for Conversation and Message by using naive_utc_now for both created_at and updated_at defaults, and for updated_at on update, while keeping the existing DB server_default as a fallback. It also adds a regression test to lock in that behavior.

From Codex

Screenshots

Before After
N/A (backend timestamp model change) N/A (backend timestamp model change)

Checklist

  • This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs)
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 9, 2026
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-07-09 08:33:39.698251192 +0000
+++ /tmp/pyrefly_pr.txt	2026-07-09 08:33:24.060098870 +0000
@@ -630,6 +630,8 @@
    --> tests/test_containers_integration_tests/controllers/mcp/test_mcp.py:458:37
 ERROR Class member `SessionMatcher.__eq__` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
   --> tests/test_containers_integration_tests/controllers/service_api/dataset/test_dataset.py:28:9
+ERROR `in` is not supported between `Literal['webapp-logo']` and `None` [not-iterable]
+   --> tests/test_containers_integration_tests/controllers/web/test_site.py:136:16
 ERROR Argument `SimpleNamespace` is not assignable to parameter `webapp_settings` with type `WebAppSettings | None` in function `controllers.web.wraps._validate_user_accessibility` [bad-argument-type]
   --> tests/test_containers_integration_tests/controllers/web/test_wraps.py:77:33
 ERROR Argument `SimpleNamespace` is not assignable to parameter `webapp_settings` with type `WebAppSettings | None` in function `controllers.web.wraps._validate_user_accessibility` [bad-argument-type]
@@ -2282,12 +2284,32 @@
    --> tests/unit_tests/controllers/service_api/app/test_hitl_service_api.py:628:33
 ERROR Argument `() -> TestHitlServiceApi.test_snapshot_events_include_pause_payload_contract._SessionContext` is not assignable to parameter `session_maker` with type `sessionmaker[Session] | None` in function `services.workflow_event_snapshot_service._build_snapshot_events` [bad-argument-type]
    --> tests/unit_tests/controllers/service_api/app/test_hitl_service_api.py:703:27
-ERROR No matching overload found for function `typing.MutableMapping.update` called with arguments: (dict[str, object]) [no-matching-overload]
-   --> tests/unit_tests/controllers/service_api/dataset/test_document.py:155:17
-ERROR Object of class `Document` has no attribute `summary_index_status` [missing-attribute]
-   --> tests/unit_tests/controllers/service_api/dataset/test_document.py:185:33
-ERROR Missing argument `session` in function `services.dataset_service.DocumentService.get_document` [missing-argument]
-   --> tests/unit_tests/controllers/service_api/dataset/test_document.py:377:46
+ERROR Argument value `Literal[0]` violates Pydantic `ge` constraint `Literal[1]` for field `limit` [bad-argument-type]
+  --> tests/unit_tests/controllers/service_api/app/test_message.py:90:63
+ERROR Argument value `Literal[101]` violates Pydantic `le` constraint `Literal[100]` for field `limit` [bad-argument-type]
+  --> tests/unit_tests/controllers/service_api/app/test_message.py:96:63
+ERROR Argument `str | None` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
+   --> tests/unit_tests/controllers/service_api/app/test_message.py:134:20
+ERROR Argument value `Literal[0]` violates Pydantic `ge` constraint `Literal[1]` for field `page` [bad-argument-type]
+   --> tests/unit_tests/controllers/service_api/app/test_message.py:166:31
+ERROR Argument value `Literal[0]` violates Pydantic `ge` constraint `Literal[1]` for field `limit` [bad-argument-type]
+   --> tests/unit_tests/controllers/service_api/app/test_message.py:179:31
+ERROR Argument value `Literal[102]` violates Pydantic `le` constraint `Literal[101]` for field `limit` [bad-argument-type]
+   --> tests/unit_tests/controllers/service_api/app/test_message.py:184:31
+ERROR Argument `list[dict[str, Any]] | None` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:111:20
+ERROR Object of class `dict` has no attribute `page` [missing-attribute]
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:219:16
+ERROR Object of class `dict` has no attribute `limit` [missing-attribute]
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:220:16
+ERROR Object of class `NoneType` has no attribute `status` [missing-attribute]
+   --> tests/unit_tests/controllers/service_api/app/test_workflow.py:351:16
+ERROR Argument `SimpleNamespace` is not assignable to parameter `obj` with type `WorkflowRun` in function `controllers.service_api.app.workflow.WorkflowRunStatusField.output` [bad-argument-type]
+  --> tests/unit_tests/controllers/service_api/app/test_workflow_fields.py:11:35
+ERROR Argument `SimpleNamespace` is not assignable to parameter `obj` with type `WorkflowRun` in function `controllers.service_api.app.workflow.WorkflowRunOutputsField.output` [bad-argument-type]
+  --> tests/unit_tests/controllers/service_api/app/test_workflow_fields.py:18:36
+ERROR Argument `SimpleNamespace` is not assignable to parameter `obj` with type `WorkflowRun` in function `controllers.service_api.app.workflow.WorkflowRunOutputsField.output` [bad-argument-type]
+  --> tests/unit_tests/controllers/service_api/app/test_workflow_fields.py:25:36
 ERROR Missing argument `app_model` in function `protected_view` [missing-argument]
    --> tests/unit_tests/controllers/service_api/test_wraps.py:160:36
 ERROR Cannot index into `object` [bad-index]
@@ -2328,6 +2350,14 @@
   --> tests/unit_tests/controllers/trigger/test_webhook.py:84:16
 ERROR Cannot index into `Response` [bad-index]
    --> tests/unit_tests/controllers/trigger/test_webhook.py:101:16
+ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.web.site.serialize_app_site_payload` [bad-argument-type]
+   --> tests/unit_tests/controllers/web/test_human_input_form.py:217:54
+ERROR Argument `SimpleNamespace` is not assignable to parameter `site` with type `Site` in function `controllers.web.site.serialize_app_site_payload` [bad-argument-type]
+   --> tests/unit_tests/controllers/web/test_human_input_form.py:217:65
+ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.web.site.serialize_app_site_payload` [bad-argument-type]
+   --> tests/unit_tests/controllers/web/test_human_input_form.py:251:54
+ERROR Argument `SimpleNamespace` is not assignable to parameter `site` with type `Site` in function `controllers.web.site.serialize_app_site_payload` [bad-argument-type]
+   --> tests/unit_tests/controllers/web/test_human_input_form.py:251:65
 ERROR Object of class `ModuleType` has no attribute `web_ns` [missing-attribute]
   --> tests/unit_tests/controllers/web/test_message_list.py:41:9
 ERROR Object of class `ModuleType` has no attribute `WebApiResource` [missing-attribute]

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 52.64% 52.59% -0.05%
Strict coverage 52.16% 52.11% -0.05%
Typed symbols 32,587 32,540 -47
Untyped symbols 29,585 29,605 +20
Modules 2982 2982 0

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

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Timezone inconsistency in message/conversation timestamps leads to 8-hour discrepancy on MySQL

1 participant