Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: Workflow start time and time zone error

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Sep 9, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Sep 9, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@shaohuzhang1 shaohuzhang1 merged commit 4cb3912 into v2 Sep 9, 2025
3 of 5 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@fix_workflow branch September 9, 2025 05:52
return {'time': timezone.localtime(timezone.now()).strftime('%Y-%m-%d %H:%M:%S'), 'start_time': time.time(),
'history_context': history_context, 'chat_id': str(chat_id), **node.workflow_manage.form_data,
'chat_user_id': body.get('chat_user_id'),
'chat_user_type': body.get('chat_user_type'),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code snippet contains a couple of improvements that I would suggest:

  1. Use datetime instead of time: The original code uses timezone.now() followed by .strftime(), which returns an ISO-formatted string. However, it's typically better to use datetime.datetime.now() with appropriate timezone handling if needed.

  2. Add type hints for arguments and variables: This can help clarify the expected types, making the function more maintainable and robust.

Here's the revised version:

import datetime
from django.utils import timezone

def get_global_variable(node) -> dict:
    # Assuming history_chat_record is defined elsewhere
    history_context = [
        {
            "question": chat_record.problem_text,
            "answer": chat_record.answer_text
        }
        for chat_record in history_chat_record
    ]
    
    chat_id = node.flow_params_serializer.data.get('chat_id')
    
    current_datetime = timezone.localtime(timezone.now())
    
    start_time = time.time()
    
    return {
        'time': current_datetime.strftime('%Y-%m-%d %H:%M:%S'),
        'start_time': start_time,
        'history_context': history_context,
        'chat_id': str(chat_id),
        **node.workflow_manage.form_data,
        'chat_user_id': body.get('chat_user_id'),
        'chat_user_type': body.get('chat_user_type'),
    }

These changes should make the code cleaner and potentially faster due to avoiding explicit conversion from one format to another unnecessarily.

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