Minor tweaks (#11249)

### What problem does this PR solve?

Fix some IDE warnings

### Type of change

- [x] Refactoring

---------

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2025-11-13 16:11:07 +08:00
committed by GitHub
parent 93422fa8cc
commit 70a0f081f6
8 changed files with 21 additions and 19 deletions

View File

@ -96,12 +96,12 @@ login_manager.init_app(app)
commands.register_commands(app) commands.register_commands(app)
def search_pages_path(pages_dir): def search_pages_path(page_path):
app_path_list = [ app_path_list = [
path for path in pages_dir.glob("*_app.py") if not path.name.startswith(".") path for path in page_path.glob("*_app.py") if not path.name.startswith(".")
] ]
api_path_list = [ api_path_list = [
path for path in pages_dir.glob("*sdk/*.py") if not path.name.startswith(".") path for path in page_path.glob("*sdk/*.py") if not path.name.startswith(".")
] ]
app_path_list.extend(api_path_list) app_path_list.extend(api_path_list)
return app_path_list return app_path_list
@ -138,7 +138,7 @@ pages_dir = [
] ]
client_urls_prefix = [ client_urls_prefix = [
register_page(path) for dir in pages_dir for path in search_pages_path(dir) register_page(path) for directory in pages_dir for path in search_pages_path(directory)
] ]
@ -177,5 +177,7 @@ def load_user(web_request):
@app.teardown_request @app.teardown_request
def _db_close(exc): def _db_close(exception):
if exception:
logging.exception(f"Request failed: {exception}")
close_connection() close_connection()

View File

@ -426,7 +426,6 @@ def test_db_connect():
try: try:
import trino import trino
import os import os
from trino.auth import BasicAuthentication
except Exception as e: except Exception as e:
return server_error_response(f"Missing dependency 'trino'. Please install: pip install trino, detail: {e}") return server_error_response(f"Missing dependency 'trino'. Please install: pip install trino, detail: {e}")
@ -438,7 +437,7 @@ def test_db_connect():
auth = None auth = None
if http_scheme == "https" and req.get("password"): if http_scheme == "https" and req.get("password"):
auth = BasicAuthentication(req.get("username") or "ragflow", req["password"]) auth = trino.BasicAuthentication(req.get("username") or "ragflow", req["password"])
conn = trino.dbapi.connect( conn = trino.dbapi.connect(
host=req["host"], host=req["host"],
@ -471,8 +470,8 @@ def test_db_connect():
@login_required @login_required
def getlistversion(canvas_id): def getlistversion(canvas_id):
try: try:
list =sorted([c.to_dict() for c in UserCanvasVersionService.list_by_canvas_id(canvas_id)], key=lambda x: x["update_time"]*-1) versions =sorted([c.to_dict() for c in UserCanvasVersionService.list_by_canvas_id(canvas_id)], key=lambda x: x["update_time"]*-1)
return get_json_result(data=list) return get_json_result(data=versions)
except Exception as e: except Exception as e:
return get_data_error_result(message=f"Error getting history files: {e}") return get_data_error_result(message=f"Error getting history files: {e}")

View File

@ -55,7 +55,6 @@ def set_connector():
"timeout_secs": int(req.get("timeout_secs", 60 * 29)), "timeout_secs": int(req.get("timeout_secs", 60 * 29)),
"status": TaskStatus.SCHEDULE, "status": TaskStatus.SCHEDULE,
} }
conn["status"] = TaskStatus.SCHEDULE
ConnectorService.save(**conn) ConnectorService.save(**conn)
time.sleep(1) time.sleep(1)

View File

@ -85,7 +85,6 @@ def get():
if not e: if not e:
return get_data_error_result(message="Conversation not found!") return get_data_error_result(message="Conversation not found!")
tenants = UserTenantService.query(user_id=current_user.id) tenants = UserTenantService.query(user_id=current_user.id)
avatar = None
for tenant in tenants: for tenant in tenants:
dialog = DialogService.query(tenant_id=tenant.tenant_id, id=conv.dialog_id) dialog = DialogService.query(tenant_id=tenant.tenant_id, id=conv.dialog_id)
if dialog and len(dialog) > 0: if dialog and len(dialog) > 0:

View File

@ -154,15 +154,15 @@ def get_kb_names(kb_ids):
@login_required @login_required
def list_dialogs(): def list_dialogs():
try: try:
diags = DialogService.query( conversations = DialogService.query(
tenant_id=current_user.id, tenant_id=current_user.id,
status=StatusEnum.VALID.value, status=StatusEnum.VALID.value,
reverse=True, reverse=True,
order_by=DialogService.model.create_time) order_by=DialogService.model.create_time)
diags = [d.to_dict() for d in diags] conversations = [d.to_dict() for d in conversations]
for d in diags: for conversation in conversations:
d["kb_ids"], d["kb_names"] = get_kb_names(d["kb_ids"]) conversation["kb_ids"], conversation["kb_names"] = get_kb_names(conversation["kb_ids"])
return get_json_result(data=diags) return get_json_result(data=conversations)
except Exception as e: except Exception as e:
return server_error_response(e) return server_error_response(e)

View File

@ -308,7 +308,7 @@ def get_filter():
@manager.route("/infos", methods=["POST"]) # noqa: F821 @manager.route("/infos", methods=["POST"]) # noqa: F821
@login_required @login_required
def docinfos(): def doc_infos():
req = request.json req = request.json
doc_ids = req["doc_ids"] doc_ids = req["doc_ids"]
for doc_id in doc_ids: for doc_id in doc_ids:
@ -544,6 +544,7 @@ def change_parser():
return get_data_error_result(message="Tenant not found!") return get_data_error_result(message="Tenant not found!")
if settings.docStoreConn.indexExist(search.index_name(tenant_id), doc.kb_id): if settings.docStoreConn.indexExist(search.index_name(tenant_id), doc.kb_id):
settings.docStoreConn.delete({"doc_id": doc.id}, search.index_name(tenant_id), doc.kb_id) settings.docStoreConn.delete({"doc_id": doc.id}, search.index_name(tenant_id), doc.kb_id)
return None
try: try:
if "pipeline_id" in req and req["pipeline_id"] != "": if "pipeline_id" in req and req["pipeline_id"] != "":

View File

@ -246,8 +246,8 @@ def rm():
try: try:
if file.location: if file.location:
settings.STORAGE_IMPL.rm(file.parent_id, file.location) settings.STORAGE_IMPL.rm(file.parent_id, file.location)
except Exception: except Exception as e:
logging.exception(f"Fail to remove object: {file.parent_id}/{file.location}") logging.exception(f"Fail to remove object: {file.parent_id}/{file.location}, error: {e}")
informs = File2DocumentService.get_by_file_id(file.id) informs = File2DocumentService.get_by_file_id(file.id)
for inform in informs: for inform in informs:

View File

@ -731,6 +731,8 @@ def delete_kb_task():
def cancel_task(task_id): def cancel_task(task_id):
REDIS_CONN.set(f"{task_id}-cancel", "x") REDIS_CONN.set(f"{task_id}-cancel", "x")
kb_task_id_field: str = ""
kb_task_finish_at: str = ""
match pipeline_task_type: match pipeline_task_type:
case PipelineTaskType.GRAPH_RAG: case PipelineTaskType.GRAPH_RAG:
kb_task_id_field = "graphrag_task_id" kb_task_id_field = "graphrag_task_id"