Skip to content

Commit 5588007

Browse files
committed
chore: replace datetime.now() with timezone.now() for consistent time handling
1 parent 6697644 commit 5588007

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

apps/application/flow/step_node/start_node/impl/base_start_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import time
1010
from datetime import datetime
1111
from typing import List, Type
12-
12+
from django.utils import timezone
1313
from rest_framework import serializers
1414

1515
from application.flow.i_step_node import NodeResult
@@ -30,7 +30,7 @@ def get_global_variable(node):
3030
history_context = [{'question': chat_record.problem_text, 'answer': chat_record.answer_text} for chat_record in
3131
history_chat_record]
3232
chat_id = node.flow_params_serializer.data.get('chat_id')
33-
return {'time': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'start_time': time.time(),
33+
return {'time': timezone.now().strftime('%Y-%m-%d %H:%M:%S'), 'start_time': time.time(),
3434
'history_context': history_context, 'chat_id': str(chat_id), **node.workflow_manage.form_data,
3535
'chat_user_id': body.get('chat_user_id'),
3636
'chat_user_type': body.get('chat_user_type'),

apps/application/serializers/application.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from django.db.models import QuerySet, Q
2323
from django.http import HttpResponse
2424
from django.utils.translation import gettext_lazy as _
25+
from django.utils import timezone
2526
from langchain_mcp_adapters.client import MultiServerMCPClient
2627
from rest_framework import serializers, status
2728
from rest_framework.utils.formatting import lazy_format
@@ -734,11 +735,11 @@ def publish(self, instance, with_valid=True):
734735
application.desc = node_data.get('desc')
735736
application.prologue = node_data.get('prologue')
736737
application.work_flow = work_flow
737-
application.publish_time = datetime.datetime.now()
738+
application.publish_time = timezone.now()
738739
application.is_publish = True
739740
application.save()
740741
work_flow_version = ApplicationVersion(work_flow=application.work_flow, application=application,
741-
name=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
742+
name=timezone.now().strftime('%Y-%m-%d %H:%M:%S'),
742743
publish_user_id=user_id,
743744
publish_user_name=user.username,
744745
workspace_id=workspace_id)

apps/common/event/listener_manage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from django.db.models import QuerySet
1717
from django.db.models.functions import Substr, Reverse
1818
from django.utils.translation import gettext_lazy as _
19+
from django.utils import timezone
1920
from langchain_core.embeddings import Embeddings
2021

2122
from common.config.embedding_config import VectorStore
@@ -236,7 +237,7 @@ def update_status(query_set: QuerySet, taskType: TaskType, state: State):
236237
next_index = taskType.value + 1
237238
current_index = taskType.value
238239
status_number = state.value
239-
current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') + '+00'
240+
current_time = timezone.now().strftime('%Y-%m-%d %H:%M:%S.%f') + '+00'
240241
params_dict = {'${bit_number}': bit_number, '${up_index}': up_index,
241242
'${status_number}': status_number, '${next_index}': next_index,
242243
'${table_name}': query_set.model._meta.db_table, '${current_index}': current_index,

apps/common/handle/impl/response/openai_to_response.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import datetime
1010

1111
from django.http import JsonResponse
12+
from django.utils import timezone
1213
from openai.types import CompletionUsage
1314
from openai.types.chat import ChatCompletionChunk, ChatCompletionMessage, ChatCompletion
1415
from openai.types.chat.chat_completion import Choice as BlockChoice
@@ -28,7 +29,7 @@ def to_block_response(self, chat_id, chat_record_id, content, is_end, completion
2829
BlockChoice(finish_reason='stop', index=0, chat_id=chat_id,
2930
answer_list=other_params.get('answer_list', ""),
3031
message=ChatCompletionMessage(role='assistant', content=content))],
31-
created=datetime.datetime.now().second, model='', object='chat.completion',
32+
created=timezone.now().second, model='', object='chat.completion',
3233
usage=CompletionUsage(completion_tokens=completion_tokens,
3334
prompt_tokens=prompt_tokens,
3435
total_tokens=completion_tokens + prompt_tokens)
@@ -41,7 +42,7 @@ def to_stream_chunk_response(self, chat_id, chat_record_id, node_id, up_node_id_
4142
if other_params is None:
4243
other_params = {}
4344
chunk = ChatCompletionChunk(id=chat_record_id, model='', object='chat.completion.chunk',
44-
created=datetime.datetime.now().second, choices=[
45+
created=timezone.now().second, choices=[
4546
Choice(delta=ChoiceDelta(content=content, reasoning_content=other_params.get('reasoning_content', ""),
4647
chat_id=chat_id),
4748
finish_reason='stop' if is_end else None,

0 commit comments

Comments
 (0)