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.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
feat: Deprecate datetime.utcnow() in favor of datetime.now(timezone.utc).replace(tzinfo=None) for better timezone handling (#3408) (#3416)
LIU HONGWEIc227f3d98566
diff --git a/api/controllers/console/app/conversation.py b/api/controllers/console/app/conversation.pyindex f7890de1cb6..71b52d5cebe 100644--- a/api/controllers/console/app/conversation.py+++ b/api/controllers/console/app/conversation.py@@ -1,4 +1,4 @@-from datetime import datetime+from datetime import datetime, timezoneimport pytzfrom flask_login import current_user@@ -262,7 +262,7 @@ def _get_conversation(app_model, conversation_id):raise NotFound("Conversation Not Exists.")if not conversation.read_at:- conversation.read_at = datetime.utcnow()+ conversation.read_at = datetime.now(timezone.utc).replace(tzinfo=None)conversation.read_account_id = current_user.iddb.session.commit()diff --git a/api/controllers/console/auth/activate.py b/api/controllers/console/auth/activate.pyindex 20e028af993..8efb55cdb64 100644--- a/api/controllers/console/auth/activate.py+++ b/api/controllers/console/auth/activate.py@@ -1,6 +1,6 @@import base64+import datetimeimport secrets-from datetime import datetimefrom flask_restful import Resource, reqparse@@ -66,7 +66,7 @@ class ActivateApi(Resource):account.timezone = args['timezone']account.interface_theme = 'light'account.status = AccountStatus.ACTIVE.value- account.initialized_at = datetime.utcnow()+ account.initialized_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)db.session.commit()return {'result': 'success'}diff --git a/api/controllers/console/auth/oauth.py b/api/controllers/console/auth/oauth.pyindex 05b1c36873a..e5b80e9a57b 100644--- a/api/controllers/console/auth/oauth.py+++ b/api/controllers/console/auth/oauth.py@@ -1,5 +1,5 @@import logging-from datetime import datetime+from datetime import datetime, timezonefrom typing import Optionalimport requests@@ -73,7 +73,7 @@ class OAuthCallback(Resource):if account.status == AccountStatus.PENDING.value:account.status = AccountStatus.ACTIVE.value- account.initialized_at = datetime.utcnow()+ account.initialized_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()TenantService.create_owner_tenant_if_not_exist(account)diff --git a/api/controllers/console/datasets/data_source.py b/api/controllers/console/datasets/data_source.pyindex f3e639c6acf..8b210cc756b 100644--- a/api/controllers/console/datasets/data_source.py+++ b/api/controllers/console/datasets/data_source.py@@ -80,7 +80,7 @@ class DataSourceApi(Resource):if action == 'enable':if data_source_binding.disabled:data_source_binding.disabled = False- data_source_binding.updated_at = datetime.datetime.utcnow()+ data_source_binding.updated_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)db.session.add(data_source_binding)db.session.commit()else:@@ -89,7 +89,7 @@ class DataSourceApi(Resource):if action == 'disable':if not data_source_binding.disabled:data_source_binding.disabled = True- data_source_binding.updated_at = datetime.datetime.utcnow()+ data_source_binding.updated_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)db.session.add(data_source_binding)db.session.commit()else:diff --git a/api/controllers/console/datasets/datasets_document.py b/api/controllers/console/datasets/datasets_document.pyindex c383cdc762a..3d6daa76825 100644--- a/api/controllers/console/datasets/datasets_document.py+++ b/api/controllers/console/datasets/datasets_document.py@@ -1,4 +1,4 @@-from datetime import datetime+from datetime import datetime, timezonefrom flask import requestfrom flask_login import current_user@@ -637,7 +637,7 @@ class DocumentProcessingApi(DocumentResource):raise InvalidActionError('Document not in indexing state.')document.paused_by = current_user.id- document.paused_at = datetime.utcnow()+ document.paused_at = datetime.now(timezone.utc).replace(tzinfo=None)document.is_paused = Truedb.session.commit()@@ -717,7 +717,7 @@ class DocumentMetadataApi(DocumentResource):document.doc_metadata[key] = valuedocument.doc_type = doc_type- document.updated_at = datetime.utcnow()+ document.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()return {'result': 'success', 'message': 'Document metadata updated.'}, 200@@ -755,7 +755,7 @@ class DocumentStatusApi(DocumentResource):document.enabled = Truedocument.disabled_at = Nonedocument.disabled_by = None- document.updated_at = datetime.utcnow()+ document.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()# Set cache to prevent indexing the same document multiple times@@ -772,9 +772,9 @@ class DocumentStatusApi(DocumentResource):raise InvalidActionError('Document already disabled.')document.enabled = False- document.disabled_at = datetime.utcnow()+ document.disabled_at = datetime.now(timezone.utc).replace(tzinfo=None)document.disabled_by = current_user.id- document.updated_at = datetime.utcnow()+ document.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()# Set cache to prevent indexing the same document multiple times@@ -789,9 +789,9 @@ class DocumentStatusApi(DocumentResource):raise InvalidActionError('Document already archived.')document.archived = True- document.archived_at = datetime.utcnow()+ document.archived_at = datetime.now(timezone.utc).replace(tzinfo=None)document.archived_by = current_user.id- document.updated_at = datetime.utcnow()+ document.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()if document.enabled:@@ -808,7 +808,7 @@ class DocumentStatusApi(DocumentResource):document.archived = Falsedocument.archived_at = Nonedocument.archived_by = None- document.updated_at = datetime.utcnow()+ document.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()# Set cache to prevent indexing the same document multiple timesdiff --git a/api/controllers/console/datasets/datasets_segments.py b/api/controllers/console/datasets/datasets_segments.pyindex 7b58120a584..0a88a0d8d44 100644--- a/api/controllers/console/datasets/datasets_segments.py+++ b/api/controllers/console/datasets/datasets_segments.py@@ -1,5 +1,5 @@import uuid-from datetime import datetime+from datetime import datetime, timezoneimport pandas as pdfrom flask import request@@ -192,7 +192,7 @@ class DatasetDocumentSegmentApi(Resource):raise InvalidActionError("Segment is already disabled.")segment.enabled = False- segment.disabled_at = datetime.utcnow()+ segment.disabled_at = datetime.now(timezone.utc).replace(tzinfo=None)segment.disabled_by = current_user.iddb.session.commit()diff --git a/api/controllers/console/explore/completion.py b/api/controllers/console/explore/completion.pyindex 292b4ed2a0e..869b56e13bf 100644--- a/api/controllers/console/explore/completion.py+++ b/api/controllers/console/explore/completion.py@@ -1,5 +1,5 @@import logging-from datetime import datetime+from datetime import datetime, timezonefrom flask_login import current_userfrom flask_restful import reqparse@@ -47,7 +47,7 @@ class CompletionApi(InstalledAppResource):streaming = args['response_mode'] == 'streaming'args['auto_generate_name'] = False- installed_app.last_used_at = datetime.utcnow()+ installed_app.last_used_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()try:@@ -110,7 +110,7 @@ class ChatApi(InstalledAppResource):args['auto_generate_name'] = False- installed_app.last_used_at = datetime.utcnow()+ installed_app.last_used_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()try:diff --git a/api/controllers/console/explore/installed_app.py b/api/controllers/console/explore/installed_app.pyindex 7d6231270f2..ec7bbed3074 100644--- a/api/controllers/console/explore/installed_app.py+++ b/api/controllers/console/explore/installed_app.py@@ -1,4 +1,4 @@-from datetime import datetime+from datetime import datetime, timezonefrom flask_login import current_userfrom flask_restful import Resource, inputs, marshal_with, reqparse@@ -81,7 +81,7 @@ class InstalledAppsListApi(Resource):tenant_id=current_tenant_id,app_owner_tenant_id=app.tenant_id,is_pinned=False,- last_used_at=datetime.utcnow()+ last_used_at=datetime.now(timezone.utc).replace(tzinfo=None))db.session.add(new_installed_app)db.session.commit()diff --git a/api/controllers/console/workspace/account.py b/api/controllers/console/workspace/account.pyindex 656a4d4cee6..198409bba78 100644--- a/api/controllers/console/workspace/account.py+++ b/api/controllers/console/workspace/account.py@@ -1,4 +1,4 @@-from datetime import datetime+import datetimeimport pytzfrom flask import current_app, request@@ -59,7 +59,7 @@ class AccountInitApi(Resource):raise InvalidInvitationCodeError()invitation_code.status = 'used'- invitation_code.used_at = datetime.utcnow()+ invitation_code.used_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)invitation_code.used_by_tenant_id = account.current_tenant_idinvitation_code.used_by_account_id = account.id@@ -67,7 +67,7 @@ class AccountInitApi(Resource):account.timezone = args['timezone']account.interface_theme = 'light'account.status = 'active'- account.initialized_at = datetime.utcnow()+ account.initialized_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)db.session.commit()return {'result': 'success'}diff --git a/api/controllers/service_api/wraps.py b/api/controllers/service_api/wraps.pyindex a75583469e6..70733d63f40 100644--- a/api/controllers/service_api/wraps.py+++ b/api/controllers/service_api/wraps.py@@ -1,5 +1,5 @@from collections.abc import Callable-from datetime import datetime+from datetime import datetime, timezonefrom enum import Enumfrom functools import wrapsfrom typing import Optional@@ -183,7 +183,7 @@ def validate_and_get_api_token(scope=None):if not api_token:raise Unauthorized("Access token is invalid")- api_token.last_used_at = datetime.utcnow()+ api_token.last_used_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()return api_tokendiff --git a/api/core/agent/base_agent_runner.py b/api/core/agent/base_agent_runner.pyindex dabc13374ae..e5b4b9a4cdf 100644--- a/api/core/agent/base_agent_runner.py+++ b/api/core/agent/base_agent_runner.py@@ -1,7 +1,7 @@import jsonimport loggingimport uuid-from datetime import datetime+from datetime import datetime, timezonefrom typing import Optional, Union, castfrom core.agent.entities import AgentEntity, AgentToolEntity@@ -440,7 +440,7 @@ class BaseAgentRunner(AppRunner):ToolConversationVariables.conversation_id == self.message.conversation_id,).first()- db_variables.updated_at = datetime.utcnow()+ db_variables.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)db_variables.variables_str = json.dumps(jsonable_encoder(tool_variables.pool))db.session.commit()db.session.close()diff --git a/api/core/app/task_pipeline/workflow_cycle_manage.py b/api/core/app/task_pipeline/workflow_cycle_manage.pyindex 49c79a5c052..48ff34fef9e 100644--- a/api/core/app/task_pipeline/workflow_cycle_manage.py+++ b/api/core/app/task_pipeline/workflow_cycle_manage.py@@ -1,6 +1,6 @@import jsonimport time-from datetime import datetime+from datetime import datetime, timezonefrom typing import Any, Optional, Union, castfrom core.app.entities.app_invoke_entities import AdvancedChatAppGenerateEntity, InvokeFrom, WorkflowAppGenerateEntity@@ -120,7 +120,7 @@ class WorkflowCycleManage:workflow_run.elapsed_time = time.perf_counter() - start_atworkflow_run.total_tokens = total_tokensworkflow_run.total_steps = total_steps- workflow_run.finished_at = datetime.utcnow()+ workflow_run.finished_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()db.session.refresh(workflow_run)@@ -149,7 +149,7 @@ class WorkflowCycleManage:workflow_run.elapsed_time = time.perf_counter() - start_atworkflow_run.total_tokens = total_tokensworkflow_run.total_steps = total_steps- workflow_run.finished_at = datetime.utcnow()+ workflow_run.finished_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()db.session.refresh(workflow_run)@@ -223,7 +223,7 @@ class WorkflowCycleManage:workflow_node_execution.outputs = json.dumps(outputs) if outputs else Noneworkflow_node_execution.execution_metadata = json.dumps(jsonable_encoder(execution_metadata)) \if execution_metadata else None- workflow_node_execution.finished_at = datetime.utcnow()+ workflow_node_execution.finished_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()db.session.refresh(workflow_node_execution)@@ -251,7 +251,7 @@ class WorkflowCycleManage:workflow_node_execution.status = WorkflowNodeExecutionStatus.FAILED.valueworkflow_node_execution.error = errorworkflow_node_execution.elapsed_time = time.perf_counter() - start_at- workflow_node_execution.finished_at = datetime.utcnow()+ workflow_node_execution.finished_at = datetime.now(timezone.utc).replace(tzinfo=None)workflow_node_execution.inputs = json.dumps(inputs) if inputs else Noneworkflow_node_execution.process_data = json.dumps(process_data) if process_data else Noneworkflow_node_execution.outputs = json.dumps(outputs) if outputs else Nonediff --git a/api/core/entities/provider_configuration.py b/api/core/entities/provider_configuration.pyindex b83ae0c8e76..303034693de 100644--- a/api/core/entities/provider_configuration.py+++ b/api/core/entities/provider_configuration.py@@ -203,7 +203,7 @@ class ProviderConfiguration(BaseModel):if provider_record:provider_record.encrypted_config = json.dumps(credentials)provider_record.is_valid = True- provider_record.updated_at = datetime.datetime.utcnow()+ provider_record.updated_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)db.session.commit()else:provider_record = Provider(@@ -351,7 +351,7 @@ class ProviderConfiguration(BaseModel):if provider_model_record:provider_model_record.encrypted_config = json.dumps(credentials)provider_model_record.is_valid = True- provider_model_record.updated_at = datetime.datetime.utcnow()+ provider_model_record.updated_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)db.session.commit()else:provider_model_record = ProviderModel(diff --git a/api/core/indexing_runner.py b/api/core/indexing_runner.pyindex 130884679b2..51e77393d66 100644--- a/api/core/indexing_runner.py+++ b/api/core/indexing_runner.py@@ -81,7 +81,7 @@ class IndexingRunner:except ProviderTokenNotInitError as e:dataset_document.indexing_status = 'error'dataset_document.error = str(e.description)- dataset_document.stopped_at = datetime.datetime.utcnow()+ dataset_document.stopped_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)db.session.commit()except ObjectDeletedError:logging.warning('Document deleted, document id: {}'.format(dataset_document.id))@@ -89,7 +89,7 @@ class IndexingRunner:logging.exception("consume document failed")dataset_document.indexing_status = 'error'dataset_document.error = str(e)- dataset_document.stopped_at = datetime.datetime.utcnow()+ dataset_document.stopped_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)db.session.commit()def run_in_splitting_status(self, dataset_document: DatasetDocument):@@ -140,13 +140,13 @@ class IndexingRunner:except ProviderTokenNotInitError as e:dataset_document.indexing_status = 'error'dataset_document.error = str(e.description)- dataset_document.stopped_at = datetime.datetime.utcnow()+ dataset_document.stopped_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)db.session.commit()except Exception as e:logging.exception("consume document failed")dataset_document.indexing_status = 'error'dataset_document.error = str(e)- dataset_document.stopped_at = datetime.datetime.utcnow()+ dataset_document.stopped_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)db.session.commit()def run_in_indexing_status(self, dataset_document: DatasetDocument):@@ -202,13 +202,13 @@ class IndexingRunner:except ProviderTokenNotInitError as e:dataset_document.indexing_status = 'error'dataset_document.error = str(e.description)- dataset_document.stopped_at = datetime.datetime.utcnow()+ dataset_document.stopped_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)db.session.commit()except Exception as e:logging.exception("consume document failed")dataset_document.indexing_status = 'error'dataset_document.error = str(e)- dataset_document.stopped_at = datetime.datetime.utcnow()+ dataset_document.stopped_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)db.session.commit()def indexing_estimate(self, tenant_id: str, extract_settings: list[ExtractSetting], tmp_processing_rule: dict,@@ -382,7 +382,7 @@ class IndexingRunner:after_indexing_status="splitting",extra_update_params={DatasetDocument.word_count: sum([len(text_doc.page_content) for text_doc in text_docs]),- DatasetDocument.parsing_completed_at: datetime.datetime.utcnow()+ DatasetDocument.parsing_completed_at: datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)})@@ -467,7 +467,7 @@ class IndexingRunner:doc_store.add_documents(documents)# update document status to indexing- cur_time = datetime.datetime.utcnow()+ cur_time = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)self._update_document_index_status(document_id=dataset_document.id,after_indexing_status="indexing",@@ -482,7 +482,7 @@ class IndexingRunner:dataset_document_id=dataset_document.id,update_params={DocumentSegment.status: "indexing",- DocumentSegment.indexing_at: datetime.datetime.utcnow()+ DocumentSegment.indexing_at: datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)})@@ -685,7 +685,7 @@ class IndexingRunner:after_indexing_status="completed",extra_update_params={DatasetDocument.tokens: tokens,- DatasetDocument.completed_at: datetime.datetime.utcnow(),+ DatasetDocument.completed_at: datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None),DatasetDocument.indexing_latency: indexing_end_at - indexing_start_at,})@@ -706,7 +706,7 @@ class IndexingRunner:).update({DocumentSegment.status: "completed",DocumentSegment.enabled: True,- DocumentSegment.completed_at: datetime.datetime.utcnow()+ DocumentSegment.completed_at: datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)})db.session.commit()@@ -739,7 +739,7 @@ class IndexingRunner:).update({DocumentSegment.status: "completed",DocumentSegment.enabled: True,- DocumentSegment.completed_at: datetime.datetime.utcnow()+ DocumentSegment.completed_at: datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)})db.session.commit()@@ -838,7 +838,7 @@ class IndexingRunner:doc_store.add_documents(documents)# update document status to indexing- cur_time = datetime.datetime.utcnow()+ cur_time = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)self._update_document_index_status(document_id=dataset_document.id,after_indexing_status="indexing",@@ -853,7 +853,7 @@ class IndexingRunner:dataset_document_id=dataset_document.id,update_params={DocumentSegment.status: "indexing",- DocumentSegment.indexing_at: datetime.datetime.utcnow()+ DocumentSegment.indexing_at: datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)})passdiff --git a/api/events/event_handlers/create_document_index.py b/api/events/event_handlers/create_document_index.pyindex 0b281c92713..68dae5a5537 100644--- a/api/events/event_handlers/create_document_index.py+++ b/api/events/event_handlers/create_document_index.py@@ -29,7 +29,7 @@ def handle(sender, **kwargs):raise NotFound('Document not found')document.indexing_status = 'parsing'- document.processing_started_at = datetime.datetime.utcnow()+ document.processing_started_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)documents.append(document)db.session.add(document)db.session.commit()diff --git a/api/events/event_handlers/update_provider_last_used_at_when_messaeg_created.py b/api/events/event_handlers/update_provider_last_used_at_when_messaeg_created.pyindex ae983cc5d1a..81cb8611808 100644--- a/api/events/event_handlers/update_provider_last_used_at_when_messaeg_created.py+++ b/api/events/event_handlers/update_provider_last_used_at_when_messaeg_created.py@@ -1,4 +1,4 @@-from datetime import datetime+from datetime import datetime, timezonefrom core.app.entities.app_invoke_entities import AgentChatAppGenerateEntity, ChatAppGenerateEntityfrom events.message_event import message_was_created@@ -17,5 +17,5 @@ def handle(sender, **kwargs):db.session.query(Provider).filter(Provider.tenant_id == application_generate_entity.app_config.tenant_id,Provider.provider_name == application_generate_entity.model_config.provider- ).update({'last_used': datetime.utcnow()})+ ).update({'last_used': datetime.now(timezone.utc).replace(tzinfo=None)})db.session.commit()diff --git a/api/extensions/ext_storage.py b/api/extensions/ext_storage.pyindex 943cf4f58d4..c2104cdf555 100644--- a/api/extensions/ext_storage.py+++ b/api/extensions/ext_storage.py@@ -2,7 +2,7 @@ import osimport shutilfrom collections.abc import Generatorfrom contextlib import closing-from datetime import datetime, timedelta+from datetime import datetime, timedelta, timezonefrom typing import Unionimport boto3@@ -38,7 +38,7 @@ class Storage:account_key=app.config.get('AZURE_BLOB_ACCOUNT_KEY'),resource_types=ResourceTypes(service=True, container=True, object=True),permission=AccountSasPermissions(read=True, write=True, delete=True, list=True, add=True, create=True),- expiry=datetime.utcnow() + timedelta(hours=1)+ expiry=datetime.now(timezone.utc).replace(tzinfo=None) + timedelta(hours=1))self.client = BlobServiceClient(account_url=app.config.get('AZURE_BLOB_ACCOUNT_URL'),credential=sas_token)diff --git a/api/models/task.py b/api/models/task.pyindex 2a1bfa124fa..618d831d8ed 100644--- a/api/models/task.py+++ b/api/models/task.py@@ -1,4 +1,4 @@-from datetime import datetime+from datetime import datetime, timezonefrom celery import states@@ -15,8 +15,8 @@ class CeleryTask(db.Model):task_id = db.Column(db.String(155), unique=True)status = db.Column(db.String(50), default=states.PENDING)result = db.Column(db.PickleType, nullable=True)- date_done = db.Column(db.DateTime, default=datetime.utcnow,- onupdate=datetime.utcnow, nullable=True)+ date_done = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc).replace(tzinfo=None),+ onupdate=lambda: datetime.now(timezone.utc).replace(tzinfo=None), nullable=True)traceback = db.Column(db.Text, nullable=True)name = db.Column(db.String(155), nullable=True)args = db.Column(db.LargeBinary, nullable=True)@@ -35,5 +35,5 @@ class CeleryTaskSet(db.Model):autoincrement=True, primary_key=True)taskset_id = db.Column(db.String(155), unique=True)result = db.Column(db.PickleType, nullable=True)- date_done = db.Column(db.DateTime, default=datetime.utcnow,+ date_done = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc).replace(tzinfo=None),nullable=True)diff --git a/api/services/account_service.py b/api/services/account_service.pyindex 8b08a5f816b..1fe8da760c8 100644--- a/api/services/account_service.py+++ b/api/services/account_service.py@@ -2,7 +2,7 @@ import base64import loggingimport secretsimport uuid-from datetime import datetime, timedelta+from datetime import datetime, timedelta, timezonefrom hashlib import sha256from typing import Any, Optional@@ -59,8 +59,8 @@ class AccountService:available_ta.current = Truedb.session.commit()- if datetime.utcnow() - account.last_active_at > timedelta(minutes=10):- account.last_active_at = datetime.utcnow()+ if datetime.now(timezone.utc).replace(tzinfo=None) - account.last_active_at > timedelta(minutes=10):+ account.last_active_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()return account@@ -70,7 +70,7 @@ class AccountService:def get_account_jwt_token(account):payload = {"user_id": account.id,- "exp": datetime.utcnow() + timedelta(days=30),+ "exp": datetime.now(timezone.utc).replace(tzinfo=None) + timedelta(days=30),"iss": current_app.config['EDITION'],"sub": 'Console API Passport',}@@ -91,7 +91,7 @@ class AccountService:if account.status == AccountStatus.PENDING.value:account.status = AccountStatus.ACTIVE.value- account.initialized_at = datetime.utcnow()+ account.initialized_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()if account.password is None or not compare_password(password, account.password, account.password_salt):@@ -163,7 +163,7 @@ class AccountService:# If it exists, update the recordaccount_integrate.open_id = open_idaccount_integrate.encrypted_token = "" # todo- account_integrate.updated_at = datetime.utcnow()+ account_integrate.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)else:# If it does not exist, create a new recordaccount_integrate = AccountIntegrate(account_id=account.id, provider=provider, open_id=open_id,@@ -197,7 +197,7 @@ class AccountService:@staticmethoddef update_last_login(account: Account, request) -> None:"""Update last login time and ip"""- account.last_login_at = datetime.utcnow()+ account.last_login_at = datetime.now(timezone.utc).replace(tzinfo=None)account.last_login_ip = get_remote_ip(request)db.session.add(account)db.session.commit()@@ -431,7 +431,7 @@ class RegisterService:password=password)account.status = AccountStatus.ACTIVE.value if not status else status.value- account.initialized_at = datetime.utcnow()+ account.initialized_at = datetime.now(timezone.utc).replace(tzinfo=None)if open_id is not None or provider is not None:AccountService.link_account_integrate(provider, open_id, account)diff --git a/api/services/annotation_service.py b/api/services/annotation_service.pyindex db4639d40b1..8b00b28c4f7 100644--- a/api/services/annotation_service.py+++ b/api/services/annotation_service.py@@ -415,7 +415,7 @@ class AppAnnotationService:raise NotFound("App annotation not found")annotation_setting.score_threshold = args['score_threshold']annotation_setting.updated_user_id = current_user.id- annotation_setting.updated_at = datetime.datetime.utcnow()+ annotation_setting.updated_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)db.session.add(annotation_setting)db.session.commit()diff --git a/api/services/app_service.py b/api/services/app_service.pyindex 673fa1e86b6..c2f7cbb02c4 100644--- a/api/services/app_service.py+++ b/api/services/app_service.py@@ -1,6 +1,6 @@import jsonimport logging-from datetime import datetime+from datetime import datetime, timezonefrom typing import castimport yaml@@ -251,7 +251,7 @@ class AppService:app.description = args.get('description', '')app.icon = args.get('icon')app.icon_background = args.get('icon_background')- app.updated_at = datetime.utcnow()+ app.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()return app@@ -264,7 +264,7 @@ class AppService::return: App instance"""app.name = name- app.updated_at = datetime.utcnow()+ app.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()return app@@ -279,7 +279,7 @@ class AppService:"""app.icon = iconapp.icon_background = icon_background- app.updated_at = datetime.utcnow()+ app.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()return app@@ -295,7 +295,7 @@ class AppService:return appapp.enable_site = enable_site- app.updated_at = datetime.utcnow()+ app.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()return app@@ -311,7 +311,7 @@ class AppService:return appapp.enable_api = enable_api- app.updated_at = datetime.utcnow()+ app.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)db.session.commit()return appdiff --git a/api/services/dataset_service.py b/api/services/dataset_service.pyindex 78b191ac31a..fe95a22cacf 100644--- a/api/services/dataset_service.py+++ b/api/services/dataset_service.py@@ -415,7 +415,7 @@ class DocumentService:# update document to be pauseddocument.is_paused = Truedocument.paused_by = current_user.id- document.paused_at = datetime.datetime.utcnow()+ document.paused_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)db.session.add(document)db.session.commit()@@ -739,7 +739,7 @@ class DocumentService:document.parsing_completed_at = Nonedocument.cleaning_completed_at = Nonedocument.splitting_completed_at = None- document.updated_at = datetime.datetime.utcnow()+ document.updated_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)document.created_from = created_fromdocument.doc_form = document_data['doc_form']db.session.add(document)@@ -1062,8 +1062,8 @@ class SegmentService:word_count=len(content),tokens=tokens,status='completed',- indexing_at=datetime.datetime.utcnow(),- completed_at=datetime.datetime.utcnow(),+ indexing_at=datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None),+ completed_at=datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None),created_by=current_user.id)if document.doc_form == 'qa_model':@@ -1078,7 +1078,7 @@ class SegmentService:except Exception as e:logging.exception("create segment index failed")segment_document.enabled = False- segment_document.disabled_at = datetime.datetime.utcnow()+ segment_document.disabled_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)segment_document.status = 'error'segment_document.error = str(e)db.session.commit()@@ -1128,8 +1128,8 @@ class SegmentService:word_count=len(content),tokens=tokens,status='completed',- indexing_at=datetime.datetime.utcnow(),- completed_at=datetime.datetime.utcnow(),+ indexing_at=datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None),+ completed_at=datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None),created_by=current_user.id)if document.doc_form == 'qa_model':@@ -1147,7 +1147,7 @@ class SegmentService:logging.exception("create segment index failed")for segment_document in segment_data_list:segment_document.enabled = False- segment_document.disabled_at = datetime.datetime.utcnow()+ segment_document.disabled_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)segment_document.status = 'error'segment_document.error = str(e)db.session.commit()@@ -1208,10 +1208,10 @@ class SegmentService:segment.word_count = len(content)segment.tokens = tokenssegment.status = 'completed'- segment.indexing_at = datetime.datetime.utcnow()- segment.completed_at = datetime.datetime.utcnow()+ segment.indexing_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)+ segment.completed_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)segment.updated_by = current_user.id- segment.updated_at = datetime.datetime.utcnow()+ segment.updated_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)if document.doc_form == 'qa_model':segment.answer = args['answer']db.session.add(segment)@@ -1221,7 +1221,7 @@ class SegmentService:except Exception as e:logging.exception("update segment index failed")segment.enabled = False- segment.disabled_at = datetime.datetime.utcnow()+ segment.disabled_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)segment.status = 'error'segment.error = str(e)db.session.commit()diff --git a/api/services/file_service.py b/api/services/file_service.pyindex ab71ef02a03..f9df21f544b 100644--- a/api/services/file_service.py+++ b/api/services/file_service.py@@ -81,7 +81,7 @@ class FileService:mime_type=file.mimetype,created_by_role=('account' if isinstance(user, Account) else 'end_user'),created_by=user.id,- created_at=datetime.datetime.utcnow(),+ created_at=datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None),used=False,hash=hashlib.sha3_256(file_content).hexdigest())@@ -111,10 +111,10 @@ class FileService:extension='txt',mime_type='text/plain',created_by=current_user.id,- created_at=datetime.datetime.utcnow(),+ created_at=datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None),used=True,used_by=current_user.id,- used_at=datetime.datetime.utcnow()+ used_at=datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None))db.session.add(upload_file)diff --git a/api/services/workflow_service.py b/api/services/workflow_service.pyindex d15c383b0b0..e1cffdd1bda 100644--- a/api/services/workflow_service.py+++ b/api/services/workflow_service.py@@ -1,6 +1,6 @@import jsonimport time-from datetime import datetime+from datetime import datetime, timezonefrom typing import Optionalfrom core.app.apps.advanced_chat.app_config_manager import AdvancedChatAppConfigManager@@ -93,7 +93,7 @@ class WorkflowService:workflow.graph = json.dumps(graph)workflow.features = json.dumps(features)workflow.updated_by = account.id- workflow.updated_at = datetime.utcnow()+ workflow.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)# commit db session changesdb.session.commit()@@ -123,7 +123,7 @@ class WorkflowService:tenant_id=app_model.tenant_id,app_id=app_model.id,type=draft_workflow.type,- version=str(datetime.utcnow()),+ version=str(datetime.now(timezone.utc).replace(tzinfo=None)),graph=draft_workflow.graph,features=draft_workflow.features,created_by=account.id@@ -202,8 +202,8 @@ class WorkflowService:elapsed_time=time.perf_counter() - start_at,created_by_role=CreatedByRole.ACCOUNT.value,created_by=account.id,- created_at=datetime.utcnow(),- finished_at=datetime.utcnow()+ created_at=datetime.now(timezone.utc).replace(tzinfo=None),+ finished_at=datetime.now(timezone.utc).replace(tzinfo=None))db.session.add(workflow_node_execution)db.session.commit()@@ -230,8 +230,8 @@ class WorkflowService:elapsed_time=time.perf_counter() - start_at,created_by_role=CreatedByRole.ACCOUNT.value,created_by=account.id,- created_at=datetime.utcnow(),- finished_at=datetime.utcnow()+ created_at=datetime.now(timezone.utc).replace(tzinfo=None),+ finished_at=datetime.now(timezone.utc).replace(tzinfo=None))else:# create workflow node execution@@ -249,8 +249,8 @@ class WorkflowService:elapsed_time=time.perf_counter() - start_at,created_by_role=CreatedByRole.ACCOUNT.value,created_by=account.id,- created_at=datetime.utcnow(),- finished_at=datetime.utcnow()+ created_at=datetime.now(timezone.utc).replace(tzinfo=None),+ finished_at=datetime.now(timezone.utc).replace(tzinfo=None))db.session.add(workflow_node_execution)diff --git a/api/tasks/add_document_to_index_task.py b/api/tasks/add_document_to_index_task.pyindex a26ecf5526b..e0a1b219095 100644--- a/api/tasks/add_document_to_index_task.py+++ b/api/tasks/add_document_to_index_task.py@@ -70,7 +70,7 @@ def add_document_to_index_task(dataset_document_id: str):except Exception as e:logging.exception("add document to index failed")dataset_document.enabled = False- dataset_document.disabled_at = datetime.datetime.utcnow()+ dataset_document.disabled_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)dataset_document.status = 'error'dataset_document.error = str(e)db.session.commit()diff --git a/api/tasks/annotation/enable_annotation_reply_task.py b/api/tasks/annotation/enable_annotation_reply_task.pyindex 666fa8692fb..fda8b7a250f 100644--- a/api/tasks/annotation/enable_annotation_reply_task.py+++ b/api/tasks/annotation/enable_annotation_reply_task.py@@ -50,7 +50,7 @@ def enable_annotation_reply_task(job_id: str, app_id: str, user_id: str, tenant_annotation_setting.score_threshold = score_thresholdannotation_setting.collection_binding_id = dataset_collection_binding.idannotation_setting.updated_user_id = user_id- annotation_setting.updated_at = datetime.datetime.utcnow()+ annotation_setting.updated_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)db.session.add(annotation_setting)else:new_app_annotation_setting = AppAnnotationSetting(diff --git a/api/tasks/batch_create_segment_to_index_task.py b/api/tasks/batch_create_segment_to_index_task.pyindex 9e41c6aee31..d6dc970477c 100644--- a/api/tasks/batch_create_segment_to_index_task.py+++ b/api/tasks/batch_create_segment_to_index_task.py@@ -85,9 +85,9 @@ def batch_create_segment_to_index_task(job_id: str, content: list, dataset_id: sword_count=len(content),tokens=tokens,created_by=user_id,- indexing_at=datetime.datetime.utcnow(),+ indexing_at=datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None),status='completed',- completed_at=datetime.datetime.utcnow()+ completed_at=datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None))if dataset_document.doc_form == 'qa_model':segment_document.answer = segment['answer']diff --git a/api/tasks/create_segment_to_index_task.py b/api/tasks/create_segment_to_index_task.pyindex f33a1e91bf7..d31286e4cc4 100644--- a/api/tasks/create_segment_to_index_task.py+++ b/api/tasks/create_segment_to_index_task.py@@ -38,7 +38,7 @@ def create_segment_to_index_task(segment_id: str, keywords: Optional[list[str]]# update segment status to indexingupdate_params = {DocumentSegment.status: "indexing",- DocumentSegment.indexing_at: datetime.datetime.utcnow()+ DocumentSegment.indexing_at: datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)}DocumentSegment.query.filter_by(id=segment.id).update(update_params)db.session.commit()@@ -75,7 +75,7 @@ def create_segment_to_index_task(segment_id: str, keywords: Optional[list[str]]# update segment to completedupdate_params = {DocumentSegment.status: "completed",- DocumentSegment.completed_at: datetime.datetime.utcnow()+ DocumentSegment.completed_at: datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)}DocumentSegment.query.filter_by(id=segment.id).update(update_params)db.session.commit()@@ -85,7 +85,7 @@ def create_segment_to_index_task(segment_id: str, keywords: Optional[list[str]]except Exception as e:logging.exception("create segment to index failed")segment.enabled = False- segment.disabled_at = datetime.datetime.utcnow()+ segment.disabled_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)segment.status = 'error'segment.error = str(e)db.session.commit()diff --git a/api/tasks/document_indexing_sync_task.py b/api/tasks/document_indexing_sync_task.pyindex a646158dbd3..c35c18799a6 100644--- a/api/tasks/document_indexing_sync_task.py+++ b/api/tasks/document_indexing_sync_task.py@@ -67,7 +67,7 @@ def document_indexing_sync_task(dataset_id: str, document_id: str):# check the page is updatedif last_edited_time != page_edited_time:document.indexing_status = 'parsing'- document.processing_started_at = datetime.datetime.utcnow()+ document.processing_started_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)db.session.commit()# delete all document segment and indexdiff --git a/api/tasks/document_indexing_task.py b/api/tasks/document_indexing_task.pyindex b7762070503..43d1cc13f90 100644--- a/api/tasks/document_indexing_task.py+++ b/api/tasks/document_indexing_task.py@@ -47,7 +47,7 @@ def document_indexing_task(dataset_id: str, document_ids: list):if document:document.indexing_status = 'error'document.error = str(e)- document.stopped_at = datetime.datetime.utcnow()+ document.stopped_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)db.session.add(document)db.session.commit()return@@ -62,7 +62,7 @@ def document_indexing_task(dataset_id: str, document_ids: list):if document:document.indexing_status = 'parsing'- document.processing_started_at = datetime.datetime.utcnow()+ document.processing_started_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)documents.append(document)db.session.add(document)db.session.commit()diff --git a/api/tasks/document_indexing_update_task.py b/api/tasks/document_indexing_update_task.pyindex e59c549a65f..b27274be37e 100644--- a/api/tasks/document_indexing_update_task.py+++ b/api/tasks/document_indexing_update_task.py@@ -33,7 +33,7 @@ def document_indexing_update_task(dataset_id: str, document_id: str):raise NotFound('Document not found')document.indexing_status = 'parsing'- document.processing_started_at = datetime.datetime.utcnow()+ document.processing_started_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)db.session.commit()# delete all document segment and indexdiff --git a/api/tasks/enable_segment_to_index_task.py b/api/tasks/enable_segment_to_index_task.pyindex a6254a822d1..e37c06855d4 100644--- a/api/tasks/enable_segment_to_index_task.py+++ b/api/tasks/enable_segment_to_index_task.py@@ -69,7 +69,7 @@ def enable_segment_to_index_task(segment_id: str):except Exception as e:logging.exception("enable segment to index failed")segment.enabled = False- segment.disabled_at = datetime.datetime.utcnow()+ segment.disabled_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)segment.status = 'error'segment.error = str(e)db.session.commit()