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(console): keep conversation updated_at unchanged when marking read (#32133)

weiguang li697b57631ab8
diff --git a/api/controllers/console/app/conversation.py b/api/controllers/console/app/conversation.py
index c8b4e83ae67..5eb61493c38 100644
--- a/api/controllers/console/app/conversation.py
+++ b/api/controllers/console/app/conversation.py
@@ -599,7 +599,12 @@ def _get_conversation(app_model, conversation_id):
db.session.execute(
sa.update(Conversation)
.where(Conversation.id == conversation_id, Conversation.read_at.is_(None))
- .values(read_at=naive_utc_now(), read_account_id=current_user.id)
+ # Keep updated_at unchanged when only marking a conversation as read.
+ .values(
+ read_at=naive_utc_now(),
+ read_account_id=current_user.id,
+ updated_at=Conversation.updated_at,
+ )
)
db.session.commit()
db.session.refresh(conversation)
diff --git a/api/tests/unit_tests/controllers/console/app/test_conversation_read_timestamp.py b/api/tests/unit_tests/controllers/console/app/test_conversation_read_timestamp.py
new file mode 100644
index 00000000000..7bab73d6c6d
--- /dev/null
+++ b/api/tests/unit_tests/controllers/console/app/test_conversation_read_timestamp.py
@@ -0,0 +1,34 @@
+from datetime import datetime
+from types import SimpleNamespace
+from unittest.mock import MagicMock, patch
+
+from controllers.console.app.conversation import _get_conversation
+
+
+def test_get_conversation_mark_read_keeps_updated_at_unchanged():
+ app_model = SimpleNamespace(id="app-id")
+ account = SimpleNamespace(id="account-id")
+ conversation = MagicMock()
+ conversation.id = "conversation-id"
+
+ with (
+ patch("controllers.console.app.conversation.current_account_with_tenant", return_value=(account, None)),
+ patch("controllers.console.app.conversation.naive_utc_now", return_value=datetime(2026, 2, 9, 0, 0, 0)),
+ patch("controllers.console.app.conversation.db.session") as mock_session,
+ ):
+ mock_session.query.return_value.where.return_value.first.return_value = conversation
+
+ _get_conversation(app_model, "conversation-id")
+
+ statement = mock_session.execute.call_args[0][0]
+ compiled = statement.compile()
+ sql_text = str(compiled).lower()
+ compact_sql_text = sql_text.replace(" ", "")
+ params = compiled.params
+
+ assert "updated_at=current_timestamp" not in compact_sql_text
+ assert "updated_at=conversations.updated_at" in compact_sql_text
+ assert "read_at=:read_at" in compact_sql_text
+ assert "read_account_id=:read_account_id" in compact_sql_text
+ assert params["read_at"] == datetime(2026, 2, 9, 0, 0, 0)
+ assert params["read_account_id"] == "account-id"