Skip to content

Commit

Permalink
auto fixes by ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenliang123 committed Nov 8, 2024
1 parent 92693f8 commit d491e87
Show file tree
Hide file tree
Showing 45 changed files with 145 additions and 145 deletions.
4 changes: 2 additions & 2 deletions api/controllers/console/app/conversation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timezone
from datetime import UTC, datetime

import pytz
from flask_login import current_user
Expand Down Expand Up @@ -314,7 +314,7 @@ def _get_conversation(app_model, conversation_id):
raise NotFound("Conversation Not Exists.")

if not conversation.read_at:
conversation.read_at = datetime.now(timezone.utc).replace(tzinfo=None)
conversation.read_at = datetime.now(UTC).replace(tzinfo=None)
conversation.read_account_id = current_user.id
db.session.commit()

Expand Down
6 changes: 3 additions & 3 deletions api/controllers/console/app/site.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timezone
from datetime import UTC, datetime

from flask_login import current_user
from flask_restful import Resource, marshal_with, reqparse
Expand Down Expand Up @@ -75,7 +75,7 @@ def post(self, app_model):
setattr(site, attr_name, value)

site.updated_by = current_user.id
site.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
site.updated_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

return site
Expand All @@ -99,7 +99,7 @@ def post(self, app_model):

site.code = Site.generate_code(16)
site.updated_by = current_user.id
site.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
site.updated_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

return site
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/console/auth/activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def post(self):
account.timezone = args["timezone"]
account.interface_theme = "light"
account.status = AccountStatus.ACTIVE.value
account.initialized_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
account.initialized_at = datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
db.session.commit()

token_pair = AccountService.login(account, ip_address=extract_remote_ip(request))
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/console/auth/oauth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from datetime import datetime, timezone
from datetime import UTC, datetime
from typing import Optional

import requests
Expand Down Expand Up @@ -106,7 +106,7 @@ def get(self, provider: str):

if account.status == AccountStatus.PENDING.value:
account.status = AccountStatus.ACTIVE.value
account.initialized_at = datetime.now(timezone.utc).replace(tzinfo=None)
account.initialized_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

try:
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/console/datasets/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def patch(self, binding_id, action):
if action == "enable":
if data_source_binding.disabled:
data_source_binding.disabled = False
data_source_binding.updated_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
data_source_binding.updated_at = datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
db.session.add(data_source_binding)
db.session.commit()
else:
Expand All @@ -92,7 +92,7 @@ def patch(self, binding_id, action):
if action == "disable":
if not data_source_binding.disabled:
data_source_binding.disabled = True
data_source_binding.updated_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
data_source_binding.updated_at = datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
db.session.add(data_source_binding)
db.session.commit()
else:
Expand Down
18 changes: 9 additions & 9 deletions api/controllers/console/datasets/datasets_document.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from argparse import ArgumentTypeError
from datetime import datetime, timezone
from datetime import UTC, datetime

from flask import request
from flask_login import current_user
Expand Down Expand Up @@ -665,7 +665,7 @@ def patch(self, dataset_id, document_id, action):
raise InvalidActionError("Document not in indexing state.")

document.paused_by = current_user.id
document.paused_at = datetime.now(timezone.utc).replace(tzinfo=None)
document.paused_at = datetime.now(UTC).replace(tzinfo=None)
document.is_paused = True
db.session.commit()

Expand Down Expand Up @@ -745,7 +745,7 @@ def put(self, dataset_id, document_id):
document.doc_metadata[key] = value

document.doc_type = doc_type
document.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
document.updated_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

return {"result": "success", "message": "Document metadata updated."}, 200
Expand Down Expand Up @@ -787,7 +787,7 @@ def patch(self, dataset_id, document_id, action):
document.enabled = True
document.disabled_at = None
document.disabled_by = None
document.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
document.updated_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

# Set cache to prevent indexing the same document multiple times
Expand All @@ -804,9 +804,9 @@ def patch(self, dataset_id, document_id, action):
raise InvalidActionError("Document already disabled.")

document.enabled = False
document.disabled_at = datetime.now(timezone.utc).replace(tzinfo=None)
document.disabled_at = datetime.now(UTC).replace(tzinfo=None)
document.disabled_by = current_user.id
document.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
document.updated_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

# Set cache to prevent indexing the same document multiple times
Expand All @@ -821,9 +821,9 @@ def patch(self, dataset_id, document_id, action):
raise InvalidActionError("Document already archived.")

document.archived = True
document.archived_at = datetime.now(timezone.utc).replace(tzinfo=None)
document.archived_at = datetime.now(UTC).replace(tzinfo=None)
document.archived_by = current_user.id
document.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
document.updated_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

if document.enabled:
Expand All @@ -840,7 +840,7 @@ def patch(self, dataset_id, document_id, action):
document.archived = False
document.archived_at = None
document.archived_by = None
document.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
document.updated_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

# Set cache to prevent indexing the same document multiple times
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/console/datasets/datasets_segments.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import uuid
from datetime import datetime, timezone
from datetime import UTC, datetime

import pandas as pd
from flask import request
Expand Down Expand Up @@ -188,7 +188,7 @@ def patch(self, dataset_id, segment_id, action):
raise InvalidActionError("Segment is already disabled.")

segment.enabled = False
segment.disabled_at = datetime.now(timezone.utc).replace(tzinfo=None)
segment.disabled_at = datetime.now(UTC).replace(tzinfo=None)
segment.disabled_by = current_user.id
db.session.commit()

Expand Down
6 changes: 3 additions & 3 deletions api/controllers/console/explore/completion.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from datetime import datetime, timezone
from datetime import UTC, datetime

from flask_login import current_user
from flask_restful import reqparse
Expand Down Expand Up @@ -46,7 +46,7 @@ def post(self, installed_app):
streaming = args["response_mode"] == "streaming"
args["auto_generate_name"] = False

installed_app.last_used_at = datetime.now(timezone.utc).replace(tzinfo=None)
installed_app.last_used_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

try:
Expand Down Expand Up @@ -106,7 +106,7 @@ def post(self, installed_app):

args["auto_generate_name"] = False

installed_app.last_used_at = datetime.now(timezone.utc).replace(tzinfo=None)
installed_app.last_used_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

try:
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/console/explore/installed_app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timezone
from datetime import UTC, datetime

from flask_login import current_user
from flask_restful import Resource, inputs, marshal_with, reqparse
Expand Down Expand Up @@ -81,7 +81,7 @@ def post(self):
tenant_id=current_tenant_id,
app_owner_tenant_id=app.tenant_id,
is_pinned=False,
last_used_at=datetime.now(timezone.utc).replace(tzinfo=None),
last_used_at=datetime.now(UTC).replace(tzinfo=None),
)
db.session.add(new_installed_app)
db.session.commit()
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/console/workspace/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ def post(self):
raise InvalidInvitationCodeError()

invitation_code.status = "used"
invitation_code.used_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
invitation_code.used_at = datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
invitation_code.used_by_tenant_id = account.current_tenant_id
invitation_code.used_by_account_id = account.id

account.interface_language = args["interface_language"]
account.timezone = args["timezone"]
account.interface_theme = "light"
account.status = "active"
account.initialized_at = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
account.initialized_at = datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
db.session.commit()

return {"result": "success"}
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/service_api/wraps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Callable
from datetime import datetime, timezone
from datetime import UTC, datetime
from enum import Enum
from functools import wraps
from typing import Optional
Expand Down Expand Up @@ -198,7 +198,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.now(timezone.utc).replace(tzinfo=None)
api_token.last_used_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

return api_token
Expand Down
4 changes: 2 additions & 2 deletions api/core/agent/base_agent_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import uuid
from collections.abc import Mapping, Sequence
from datetime import datetime, timezone
from datetime import UTC, datetime
from typing import Optional, Union, cast

from core.agent.entities import AgentEntity, AgentToolEntity
Expand Down Expand Up @@ -419,7 +419,7 @@ def update_db_variables(self, tool_variables: ToolRuntimeVariablePool, db_variab
.first()
)

db_variables.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
db_variables.updated_at = datetime.now(UTC).replace(tzinfo=None)
db_variables.variables_str = json.dumps(jsonable_encoder(tool_variables.pool))
db.session.commit()
db.session.close()
Expand Down
4 changes: 2 additions & 2 deletions api/core/app/apps/message_based_app_generator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import logging
from collections.abc import Generator
from datetime import datetime, timezone
from datetime import UTC, datetime
from typing import Optional, Union

from sqlalchemy import and_
Expand Down Expand Up @@ -200,7 +200,7 @@ def _init_generate_records(
db.session.commit()
db.session.refresh(conversation)
else:
conversation.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
conversation.updated_at = datetime.now(UTC).replace(tzinfo=None)
db.session.commit()

message = Message(
Expand Down
16 changes: 8 additions & 8 deletions api/core/app/task_pipeline/workflow_cycle_manage.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import time
from collections.abc import Mapping, Sequence
from datetime import datetime, timezone
from datetime import UTC, datetime
from typing import Any, Optional, Union, cast

from sqlalchemy.orm import Session
Expand Down Expand Up @@ -144,7 +144,7 @@ def _handle_workflow_run_success(
workflow_run.elapsed_time = time.perf_counter() - start_at
workflow_run.total_tokens = total_tokens
workflow_run.total_steps = total_steps
workflow_run.finished_at = datetime.now(timezone.utc).replace(tzinfo=None)
workflow_run.finished_at = datetime.now(UTC).replace(tzinfo=None)

db.session.commit()
db.session.refresh(workflow_run)
Expand Down Expand Up @@ -191,7 +191,7 @@ def _handle_workflow_run_failed(
workflow_run.elapsed_time = time.perf_counter() - start_at
workflow_run.total_tokens = total_tokens
workflow_run.total_steps = total_steps
workflow_run.finished_at = datetime.now(timezone.utc).replace(tzinfo=None)
workflow_run.finished_at = datetime.now(UTC).replace(tzinfo=None)

db.session.commit()

Expand All @@ -211,7 +211,7 @@ def _handle_workflow_run_failed(
for workflow_node_execution in running_workflow_node_executions:
workflow_node_execution.status = WorkflowNodeExecutionStatus.FAILED.value
workflow_node_execution.error = error
workflow_node_execution.finished_at = datetime.now(timezone.utc).replace(tzinfo=None)
workflow_node_execution.finished_at = datetime.now(UTC).replace(tzinfo=None)
workflow_node_execution.elapsed_time = (
workflow_node_execution.finished_at - workflow_node_execution.created_at
).total_seconds()
Expand Down Expand Up @@ -259,7 +259,7 @@ def _handle_node_execution_start(
NodeRunMetadataKey.ITERATION_ID: event.in_iteration_id,
}
)
workflow_node_execution.created_at = datetime.now(timezone.utc).replace(tzinfo=None)
workflow_node_execution.created_at = datetime.now(UTC).replace(tzinfo=None)

session.add(workflow_node_execution)
session.commit()
Expand All @@ -282,7 +282,7 @@ def _handle_workflow_node_execution_success(self, event: QueueNodeSucceededEvent
execution_metadata = (
json.dumps(jsonable_encoder(event.execution_metadata)) if event.execution_metadata else None
)
finished_at = datetime.now(timezone.utc).replace(tzinfo=None)
finished_at = datetime.now(UTC).replace(tzinfo=None)
elapsed_time = (finished_at - event.start_at).total_seconds()

db.session.query(WorkflowNodeExecution).filter(WorkflowNodeExecution.id == workflow_node_execution.id).update(
Expand Down Expand Up @@ -326,7 +326,7 @@ def _handle_workflow_node_execution_failed(
inputs = WorkflowEntry.handle_special_values(event.inputs)
process_data = WorkflowEntry.handle_special_values(event.process_data)
outputs = WorkflowEntry.handle_special_values(event.outputs)
finished_at = datetime.now(timezone.utc).replace(tzinfo=None)
finished_at = datetime.now(UTC).replace(tzinfo=None)
elapsed_time = (finished_at - event.start_at).total_seconds()
execution_metadata = (
json.dumps(jsonable_encoder(event.execution_metadata)) if event.execution_metadata else None
Expand Down Expand Up @@ -653,7 +653,7 @@ def _workflow_iteration_completed_to_stream_response(
if event.error is None
else WorkflowNodeExecutionStatus.FAILED,
error=None,
elapsed_time=(datetime.now(timezone.utc).replace(tzinfo=None) - event.start_at).total_seconds(),
elapsed_time=(datetime.now(UTC).replace(tzinfo=None) - event.start_at).total_seconds(),
total_tokens=event.metadata.get("total_tokens", 0) if event.metadata else 0,
execution_metadata=event.metadata,
finished_at=int(time.time()),
Expand Down
Loading

0 comments on commit d491e87

Please sign in to comment.