fix(graph-api): fix project/task dict access after ProjectManager refactor
Replace .to_dict() calls and attribute access with direct dict usage, add get_storage() import for delete_project, and rewrite reset_project to use save_project() with a partial dict instead of mutating an ORM object. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8a6d00b26e
commit
ea9ac6a1cd
|
|
@ -10,6 +10,7 @@ import threading
|
||||||
from flask import request, jsonify
|
from flask import request, jsonify
|
||||||
|
|
||||||
from . import graph_bp
|
from . import graph_bp
|
||||||
|
from .. import get_storage
|
||||||
from ..config import Config
|
from ..config import Config
|
||||||
from ..services.ontology_generator import OntologyGenerator
|
from ..services.ontology_generator import OntologyGenerator
|
||||||
from ..services.graph_builder import GraphBuilderService
|
from ..services.graph_builder import GraphBuilderService
|
||||||
|
|
@ -49,7 +50,7 @@ def get_project(project_id: str):
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"success": True,
|
"success": True,
|
||||||
"data": project.to_dict()
|
"data": project
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -63,7 +64,7 @@ def list_projects():
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"success": True,
|
"success": True,
|
||||||
"data": [p.to_dict() for p in projects],
|
"data": projects,
|
||||||
"count": len(projects)
|
"count": len(projects)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -73,7 +74,8 @@ def delete_project(project_id: str):
|
||||||
"""
|
"""
|
||||||
Delete a project
|
Delete a project
|
||||||
"""
|
"""
|
||||||
success = ProjectManager.delete_project(project_id)
|
storage = get_storage()
|
||||||
|
success = ProjectManager.delete_project(project_id, storage=storage)
|
||||||
|
|
||||||
if not success:
|
if not success:
|
||||||
return jsonify({
|
return jsonify({
|
||||||
|
|
@ -93,28 +95,25 @@ def reset_project(project_id: str):
|
||||||
Reset project status (used to rebuild the graph)
|
Reset project status (used to rebuild the graph)
|
||||||
"""
|
"""
|
||||||
project = ProjectManager.get_project(project_id)
|
project = ProjectManager.get_project(project_id)
|
||||||
|
|
||||||
if not project:
|
if not project:
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"success": False,
|
"success": False,
|
||||||
"error": t('api.projectNotFound', id=project_id)
|
"error": t('api.projectNotFound', id=project_id)
|
||||||
}), 404
|
}), 404
|
||||||
|
|
||||||
# Reset to ontology-generated status
|
new_status = ProjectStatus.ONTOLOGY_GENERATED if project.get("ontology") else ProjectStatus.CREATED
|
||||||
if project.ontology:
|
ProjectManager.save_project({
|
||||||
project.status = ProjectStatus.ONTOLOGY_GENERATED
|
"id": project_id,
|
||||||
else:
|
"status": new_status,
|
||||||
project.status = ProjectStatus.CREATED
|
"active_task_id": None,
|
||||||
|
})
|
||||||
project.graph_id = None
|
updated = ProjectManager.get_project(project_id)
|
||||||
project.graph_build_task_id = None
|
|
||||||
project.error = None
|
|
||||||
ProjectManager.save_project(project)
|
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"success": True,
|
"success": True,
|
||||||
"message": t('api.projectReset', id=project_id),
|
"message": t('api.projectReset', id=project_id),
|
||||||
"data": project.to_dict()
|
"data": updated
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -670,7 +669,7 @@ def get_task(task_id: str):
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"success": True,
|
"success": True,
|
||||||
"data": task.to_dict()
|
"data": task
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -683,7 +682,7 @@ def list_tasks():
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"success": True,
|
"success": True,
|
||||||
"data": [t.to_dict() for t in tasks],
|
"data": tasks,
|
||||||
"count": len(tasks)
|
"count": len(tasks)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue