Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Go: add context, part11 (#17426)

Jin Hai19d861b79725
diff --git a/api/apps/restful_apis/chunk_api.py b/api/apps/restful_apis/chunk_api.py
index d2aa634017..63e7a3dff7 100644
--- a/api/apps/restful_apis/chunk_api.py
+++ b/api/apps/restful_apis/chunk_api.py
@@ -209,7 +209,7 @@ async def parse(tenant_id, dataset_id):
not_found.append(id)
continue
if not doc:
- return get_error_data_result(message=f"You don't own the document {id}.")
+ return get_error_data_result(message=f"you don't own the document {id}")
info = {"run": "1", "progress": 0, "progress_msg": "", "chunk_num": 0, "token_num": 0}
if (
DocumentService.filter_update(
@@ -274,7 +274,7 @@ async def stop_parsing(tenant_id, dataset_id):
for id in doc_list:
doc = DocumentService.query(id=id, kb_id=dataset_id)
if not doc:
- return get_error_data_result(message=f"You don't own the document {id}.")
+ return get_error_data_result(message=f"you don't own the document {id}")
if doc[0].run != TaskStatus.RUNNING.value:
return construct_json_result(
code=RetCode.DATA_ERROR,
@@ -449,7 +449,7 @@ async def list_chunks(tenant_id, dataset_id, document_id):
return get_error_data_result(message=f"You don't own the dataset {dataset_id}.")
doc = DocumentService.query(id=document_id, kb_id=dataset_id)
if not doc:
- return get_error_data_result(message=f"You don't own the document {document_id}.")
+ return get_error_data_result(message=f"you don't own the document {document_id}")
doc = doc[0]
req = request.args
page = int(req.get("page", 1))
@@ -537,7 +537,7 @@ async def get_chunk(tenant_id, dataset_id, document_id, chunk_id):
return get_error_data_result(message=f"You don't own the dataset {dataset_id}.")
doc = DocumentService.query(id=document_id, kb_id=dataset_id)
if not doc:
- return get_error_data_result(message=f"You don't own the document {document_id}.")
+ return get_error_data_result(message=f"you don't own the document {document_id}")
try:
chunk = settings.docStoreConn.get(chunk_id, search.index_name(dataset_tenant_id), [dataset_id])
if chunk is None or str(chunk.get("doc_id", chunk.get("document_id"))) != str(document_id):
@@ -588,7 +588,7 @@ async def get_document_structure_graph(tenant_id, dataset_id, document_id):
return get_error_data_result(message=f"You don't own the dataset {dataset_id}.")
docs = DocumentService.query(id=document_id, kb_id=dataset_id)
if not docs:
- return get_error_data_result(message=f"You don't own the document {document_id}.")
+ return get_error_data_result(message=f"you don't own the document {document_id}")
# Resolve the doc's configured template group → child template ids
# so we can render tabs in the order the user picked them.
@@ -902,7 +902,7 @@ async def delete_document_structure_graph(tenant_id, dataset_id, document_id):
return get_error_data_result(message=f"You don't own the dataset {dataset_id}.")
docs = DocumentService.query(id=document_id, kb_id=dataset_id)
if not docs:
- return get_error_data_result(message=f"You don't own the document {document_id}.")
+ return get_error_data_result(message=f"you don't own the document {document_id}")
req = await get_request_json()
template_id = str(req.get("template_id") or "").strip()
@@ -948,7 +948,7 @@ async def add_chunk(tenant_id, dataset_id, document_id):
return get_error_data_result(message=f"You don't own the dataset {dataset_id}.")
doc = DocumentService.query(id=document_id, kb_id=dataset_id)
if not doc:
- return get_error_data_result(message=f"You don't own the document {document_id}.")
+ return get_error_data_result(message=f"you don't own the document {document_id}")
doc = doc[0]
req = await get_request_json()
if is_content_empty(req.get("content")):
@@ -1037,7 +1037,7 @@ async def rm_chunk(tenant_id, dataset_id, document_id):
return get_error_data_result(message=f"You don't own the dataset {dataset_id}.")
docs = DocumentService.query(id=document_id, kb_id=dataset_id)
if not docs:
- return get_error_data_result(message=f"You don't own the document {document_id}.")
+ return get_error_data_result(message=f"you don't own the document {document_id}")
req = await get_request_json()
if not req:
return get_result()
@@ -1091,7 +1091,7 @@ async def update_chunk(tenant_id, dataset_id, document_id, chunk_id):
return get_error_data_result(message=f"You don't own the dataset {dataset_id}.")
doc = DocumentService.query(id=document_id, kb_id=dataset_id)
if not doc:
- return get_error_data_result(message=f"You don't own the document {document_id}.")
+ return get_error_data_result(message=f"you don't own the document {document_id}")
doc = doc[0]
chunk = settings.docStoreConn.get(chunk_id, search.index_name(dataset_tenant_id), [dataset_id])
if chunk is None or str(chunk.get("doc_id", chunk.get("document_id"))) != str(document_id):
diff --git a/api/apps/restful_apis/document_api.py b/api/apps/restful_apis/document_api.py
index c258ebc7d8..0aaca3ca40 100644
--- a/api/apps/restful_apis/document_api.py
+++ b/api/apps/restful_apis/document_api.py
@@ -882,10 +882,10 @@ def _get_docs_with_request(req, dataset_id: str):
doc_id = q.get("id")
if doc_id:
if not DocumentService.query(id=doc_id, kb_id=dataset_id):
- return RetCode.DATA_ERROR, f"You don't own the document {doc_id}.", [], 0
+ return RetCode.DATA_ERROR, f"you don't own the document {doc_id}", [], 0
doc_ids_filter = [doc_id] # id provided, ignore other filters
if doc_name and not DocumentService.query(name=doc_name, kb_id=dataset_id):
- return RetCode.DATA_ERROR, f"You don't own the document {doc_name}.", [], 0
+ return RetCode.DATA_ERROR, f"you don't own the document {doc_name}", [], 0
doc_ids = q.getlist("ids")
if doc_id and len(doc_ids) > 0:
diff --git a/docs/references/http_api_reference.md b/docs/references/http_api_reference.md
index 8966dae29f..365544895c 100644
--- a/docs/references/http_api_reference.md
+++ b/docs/references/http_api_reference.md
@@ -2322,7 +2322,7 @@ Failure:
```json
{
"code": 102,
- "message": "You don't own the document 5c5999ec7be811ef9cab0242ac12000e5."
+ "message": "you don't own the document 5c5999ec7be811ef9cab0242ac12000e5"
}
```
diff --git a/internal/agent/sandbox/manager_test.go b/internal/agent/sandbox/manager_test.go
index e27507635d..cdbf5ea01e 100644
--- a/internal/agent/sandbox/manager_test.go
+++ b/internal/agent/sandbox/manager_test.go
@@ -402,7 +402,7 @@ type fakeSettingsReader struct {
fakeErr error
}
-func (f *fakeSettingsReader) GetByName(ctx context.Context, db *gorm.DB, name string) ([]entity.SystemSettings, error) {
+func (f *fakeSettingsReader) GetByName(_ context.Context, _ *gorm.DB, name string) ([]entity.SystemSettings, error) {
if f.fakeErr != nil {
return nil, f.fakeErr
}
diff --git a/internal/dao/task.go b/internal/dao/task.go
index 4f1d93b666..b97a3412ca 100644
--- a/internal/dao/task.go
+++ b/internal/dao/task.go
@@ -17,7 +17,10 @@
package dao
import (
+ "context"
"ragflow/internal/entity"
+
+ "gorm.io/gorm"
)
// TaskDAO task data access object
@@ -29,22 +32,22 @@ func NewTaskDAO() *TaskDAO {
}
// Create creates a new task
-func (dao *TaskDAO) Create(task *entity.Task) error {
- return DB.Create(task).Error
+func (dao *TaskDAO) Create(ctx context.Context, db *gorm.DB, task *entity.Task) error {
+ return db.WithContext(ctx).Create(task).Error
}
// CreateMany creates multiple tasks in one batch.
-func (dao *TaskDAO) CreateMany(tasks []*entity.Task) error {
+func (dao *TaskDAO) CreateMany(ctx context.Context, db *gorm.DB, tasks []*entity.Task) error {
if len(tasks) == 0 {
return nil
}
- return DB.Create(&tasks).Error
+ return db.WithContext(ctx).Create(&tasks).Error
}
// GetByID gets task by ID
-func (dao *TaskDAO) GetByID(id string) (*entity.Task, error) {
+func (dao *TaskDAO) GetByID(ctx context.Context, db *gorm.DB, id string) (*entity.Task, error) {
var task entity.Task
- err := DB.Where("id = ?", id).First(&task).Error
+ err := db.WithContext(ctx).Where("id = ?", id).First(&task).Error
if err != nil {
return nil, err
}
@@ -52,38 +55,38 @@ func (dao *TaskDAO) GetByID(id string) (*entity.Task, error) {
}
// DeleteIngestionTasksByDocIDs deletes ingestion tasks by document IDs (hard delete)
-func (dao *TaskDAO) DeleteIngestionTasksByDocIDs(docIDs []string) (int64, error) {
+func (dao *TaskDAO) DeleteIngestionTasksByDocIDs(ctx context.Context, db *gorm.DB, docIDs []string) (int64, error) {
if len(docIDs) == 0 {
return 0, nil
}
- result := DB.Unscoped().Where("document_id IN ?", docIDs).Delete(&entity.IngestionTask{})
+ result := db.WithContext(ctx).Unscoped().Where("document_id IN ?", docIDs).Delete(&entity.IngestionTask{})
return result.RowsAffected, result.Error
}
// DeleteByDocIDs deletes tasks by document IDs (hard delete)
-func (dao *TaskDAO) DeleteByDocIDs(docIDs []string) (int64, error) {
+func (dao *TaskDAO) DeleteByDocIDs(ctx context.Context, db *gorm.DB, docIDs []string) (int64, error) {
if len(docIDs) == 0 {
return 0, nil
}
- result := DB.Unscoped().Where("doc_id IN ?", docIDs).Delete(&entity.Task{})
+ result := db.WithContext(ctx).Unscoped().Where("doc_id IN ?", docIDs).Delete(&entity.Task{})
return result.RowsAffected, result.Error
}
// DeleteByTenantID deletes all tasks by tenant ID (hard delete via document join)
-func (dao *TaskDAO) DeleteByTenantID(tenantID string) (int64, error) {
- result := DB.Unscoped().Where("doc_id IN (SELECT id FROM document WHERE tenant_id = ?)", tenantID).Delete(&entity.Task{})
+func (dao *TaskDAO) DeleteByTenantID(ctx context.Context, db *gorm.DB, tenantID string) (int64, error) {
+ result := db.WithContext(ctx).Unscoped().Where("doc_id IN (SELECT id FROM document WHERE tenant_id = ?)", tenantID).Delete(&entity.Task{})
return result.RowsAffected, result.Error
}
// GetByDocID gets all tasks by document ID
-func (dao *TaskDAO) GetByDocID(docID string) ([]*entity.Task, error) {
+func (dao *TaskDAO) GetByDocID(ctx context.Context, db *gorm.DB, docID string) ([]*entity.Task, error) {
var tasks []*entity.Task
- err := DB.Where("doc_id = ?", docID).Order("from_page ASC, create_time ASC").Find(&tasks).Error
+ err := db.WithContext(ctx).Where("doc_id = ?", docID).Order("from_page ASC, create_time ASC").Find(&tasks).Error
return tasks, err
}
-func (dao *TaskDAO) GetAllTasks() ([]*entity.Task, error) {
+func (dao *TaskDAO) GetAllTasks(ctx context.Context, db *gorm.DB) ([]*entity.Task, error) {
var tasks []*entity.Task
- err := DB.Find(&tasks).Error
+ err := db.WithContext(ctx).Find(&tasks).Error
return tasks, err
}
diff --git a/internal/dao/task_test.go b/internal/dao/task_test.go
index 882c1411a2..710ff90190 100644
--- a/internal/dao/task_test.go
+++ b/internal/dao/task_test.go
@@ -63,18 +63,19 @@ func TestGetByDocID_FindsTasks(t *testing.T) {
t.Cleanup(func() { DB = orig })
dao := NewTaskDAO()
+ ctx := t.Context()
// Insert tasks for two different documents
task1 := &entity.Task{ID: "task-1", DocID: "doc-1"}
task2 := &entity.Task{ID: "task-2", DocID: "doc-1"}
task3 := &entity.Task{ID: "task-3", DocID: "doc-2"}
for _, tk := range []*entity.Task{task1, task2, task3} {
- if err := dao.Create(tk); err != nil {
+ if err := dao.Create(ctx, db, tk); err != nil {
t.Fatalf("failed to create task: %v", err)
}
}
- tasks, err := dao.GetByDocID("doc-1")
+ tasks, err := dao.GetByDocID(ctx, db, "doc-1")
if err != nil {
t.Fatalf("GetByDocID failed: %v", err)
}
@@ -99,8 +100,9 @@ func TestGetByDocID_NoTasks(t *testing.T) {
t.Cleanup(func() { DB = orig })
dao := NewTaskDAO()
+ ctx := t.Context()
- tasks, err := dao.GetByDocID("nonexistent")
+ tasks, err := dao.GetByDocID(ctx, db, "nonexistent")
if err != nil {
t.Fatalf("GetByDocID failed: %v", err)
}
@@ -116,14 +118,15 @@ func TestGetByDocID_EmptyDocID(t *testing.T) {
t.Cleanup(func() { DB = orig })
dao := NewTaskDAO()
+ ctx := t.Context()
// Insert a task with empty doc_id to verify edge case
task := &entity.Task{ID: "task-1", DocID: ""}
- if err := dao.Create(task); err != nil {
+ if err := dao.Create(ctx, db, task); err != nil {
t.Fatalf("failed to create task: %v", err)
}
- tasks, err := dao.GetByDocID("")
+ tasks, err := dao.GetByDocID(ctx, db, "")
if err != nil {
t.Fatalf("GetByDocID failed: %v", err)
}
@@ -151,9 +154,10 @@ func TestDeleteIngestionTasksByDocIDs_Success(t *testing.T) {
t.Fatalf("failed to create ingestion task: %v", err)
}
}
+ ctx := t.Context()
// Delete tasks for doc-1
- rowsAffected, err := dao.DeleteIngestionTasksByDocIDs([]string{"doc-1"})
+ rowsAffected, err := dao.DeleteIngestionTasksByDocIDs(ctx, db, []string{"doc-1"})
if err != nil {
t.Fatalf("DeleteIngestionTasksByDocIDs failed: %v", err)
}
@@ -181,8 +185,9 @@ func TestDeleteIngestionTasksByDocIDs_EmptyIDs(t *testing.T) {
t.Cleanup(func() { DB = orig })
dao := NewTaskDAO()
+ ctx := t.Context()
- rowsAffected, err := dao.DeleteIngestionTasksByDocIDs([]string{})
+ rowsAffected, err := dao.DeleteIngestionTasksByDocIDs(ctx, db, []string{})
if err != nil {
t.Fatalf("DeleteIngestionTasksByDocIDs failed: %v", err)
}
@@ -204,8 +209,9 @@ func TestDeleteIngestionTasksByDocIDs_Nonexistent(t *testing.T) {
if err := db.Create(task).Error; err != nil {
t.Fatalf("failed to create ingestion task: %v", err)
}
+ ctx := t.Context()
- rowsAffected, err := dao.DeleteIngestionTasksByDocIDs([]string{"nonexistent"})
+ rowsAffected, err := dao.DeleteIngestionTasksByDocIDs(ctx, db, []string{"nonexistent"})
if err != nil {
t.Fatalf("DeleteIngestionTasksByDocIDs failed: %v", err)
}
@@ -234,9 +240,10 @@ func TestDeleteIngestionTasksByDocIDs_MultipleIDs(t *testing.T) {
t.Fatalf("failed to create ingestion task: %v", err)
}
}
+ ctx := t.Context()
// Delete multiple document IDs
- rowsAffected, err := dao.DeleteIngestionTasksByDocIDs([]string{"doc-1", "doc-2", "doc-3"})
+ rowsAffected, err := dao.DeleteIngestionTasksByDocIDs(ctx, db, []string{"doc-1", "doc-2", "doc-3"})
if err != nil {
t.Fatalf("DeleteIngestionTasksByDocIDs failed: %v", err)
}
@@ -246,7 +253,7 @@ func TestDeleteIngestionTasksByDocIDs_MultipleIDs(t *testing.T) {
// Verify only "keep" remains
var remaining []*entity.IngestionTask
- if err := db.Find(&remaining).Error; err != nil {
+ if err = db.Find(&remaining).Error; err != nil {
t.Fatalf("failed to find remaining tasks: %v", err)
}
if len(remaining) != 1 || remaining[0].ID != "itask-4" {
diff --git a/internal/service/chunk/chunk.go b/internal/service/chunk/chunk.go
index 5376c31db1..1c3342046f 100644
--- a/internal/service/chunk/chunk.go
+++ b/internal/service/chunk/chunk.go
@@ -1291,7 +1291,7 @@ func (s *ChunkService) AddChunk(ctx context.Context, req *service.AddChunkReques
doc, err := s.documentDAO.GetByDocumentIDAndDatasetID(ctx, dao.DB, req.DocumentID, req.DatasetID)
if err != nil || doc == nil {
- return nil, addChunkError{code: common.CodeDataError, message: fmt.Sprintf("You don't own the document %s.", req.DocumentID)}
+ return nil, addChunkError{code: common.CodeDataError, message: fmt.Sprintf("you don't own the document %s", req.DocumentID)}
}
content := strings.TrimSpace(req.Content)
diff --git a/internal/service/chunk_types.go b/internal/service/chunk_types.go
index 6229a26f16..69a6ac3e7f 100644
--- a/internal/service/chunk_types.go
+++ b/internal/service/chunk_types.go
@@ -209,8 +209,8 @@ type StopParsingResponse struct {
Message string
}
-func (s *ChunkService) cancelAllTasksOfDoc(docID string) error {
- tasks, err := s.taskDAO.GetByDocID(docID)
+func (s *ChunkService) cancelAllTasksOfDoc(ctx context.Context, docID string) error {
+ tasks, err := s.taskDAO.GetByDocID(ctx, dao.DB, docID)
if err != nil {
return fmt.Errorf("failed to get tasks for document %s: %w", docID, err)
}
@@ -274,17 +274,17 @@ func (s *ChunkService) StopParsing(ctx context.Context, userID, datasetID string
var doc *entity.Document
doc, err = s.documentDAO.GetByDocumentIDAndDatasetID(ctx, dao.DB, id, datasetID)
if err != nil {
- return nil, common.CodeDataError, fmt.Errorf("You don't own the document %s", id)
+ return nil, common.CodeDataError, fmt.Errorf("you don't own the document %s", id)
}
if doc == nil {
- return nil, common.CodeDataError, fmt.Errorf("You don't own the document %s", id)
+ return nil, common.CodeDataError, fmt.Errorf("you don't own the document %s", id)
}
if doc.Run == nil || *doc.Run != RUNNING {
- return nil, common.CodeDataError, fmt.Errorf("Can't stop parsing document that has not started or already completed")
+ return nil, common.CodeDataError, fmt.Errorf("can't stop parsing document that has not started or already completed")
}
- err = s.cancelAllTasksOfDoc(id)
+ err = s.cancelAllTasksOfDoc(ctx, id)
if err != nil {
return nil, common.CodeServerError, err
}
diff --git a/internal/service/dataset/index.go b/internal/service/dataset/index.go
index ed6200734f..2c4d584be5 100644
--- a/internal/service/dataset/index.go
+++ b/internal/service/dataset/index.go
@@ -390,7 +390,7 @@ func (d *DatasetService) TraceIndex(ctx context.Context, datasetID, userID, inde
var task *entity.Task
if taskID != "" {
- task, err = d.taskDAO.GetByID(taskID)
+ task, err = d.taskDAO.GetByID(ctx, dao.DB, taskID)
if err != nil {
if dao.IsNotFoundErr(err) {
return nil, common.CodeSuccess, nil
diff --git a/internal/service/document/document_crud.go b/internal/service/document/document_crud.go
index b44c6a5baa..c0a16f5ad0 100644
--- a/internal/service/document/document_crud.go
+++ b/internal/service/document/document_crud.go
@@ -2,6 +2,7 @@ package document
import (
"context"
+ "errors"
"fmt"
"ragflow/internal/common"
@@ -276,10 +277,15 @@ func (s *DocumentService) RemoveDocumentKeepFile(ctx context.Context, docID stri
if err != nil {
return err
}
- if _, delErr := s.taskDAO.DeleteByDocIDs([]string{docID}); delErr != nil {
+ if _, delErr := s.taskDAO.DeleteByDocIDs(ctx, dao.DB, []string{docID}); delErr != nil {
+ common.Logger.Warn(fmt.Sprintf("RemoveDocumentKeepFile: failed to delete tasks for %s: %v", docID, delErr))
+ }
+ if _, delErr := s.taskDAO.DeleteByDocIDs(ctx, dao.DB, []string{docID}); delErr != nil {
+ if errors.Is(delErr, context.Canceled) || errors.Is(delErr, context.DeadlineExceeded) {
+ return fmt.Errorf("RemoveDocumentKeepFile: failed to delete tasks for %s: %w", docID, delErr)
+ }
common.Logger.Warn(fmt.Sprintf("RemoveDocumentKeepFile: failed to delete tasks for %s: %v", docID, delErr))
}
- s.deleteDocEngineData(docID, kb.TenantID, doc.KbID)
return s.deleteDocRecordWithCounters(ctx, doc, kb.ID)
}
diff --git a/internal/service/document/document_ingest.go b/internal/service/document/document_ingest.go
index eb398e4981..ecaf885014 100644
--- a/internal/service/document/document_ingest.go
+++ b/internal/service/document/document_ingest.go
@@ -2,6 +2,7 @@ package document
import (
"context"
+ "errors"
"fmt"
"ragflow/internal/dao"
"ragflow/internal/service"
@@ -127,7 +128,12 @@ func (s *DocumentService) Ingest(ctx context.Context, userID string, req *Ingest
}
if req.Delete {
- _, _ = s.taskDAO.DeleteIngestionTasksByDocIDs([]string{doc.ID})
+ if _, delErr := s.taskDAO.DeleteIngestionTasksByDocIDs(ctx, dao.DB, []string{doc.ID}); delErr != nil {
+ if errors.Is(delErr, context.Canceled) || errors.Is(delErr, context.DeadlineExceeded) {
+ return common.CodeExceptionError, fmt.Errorf("delete ingestion tasks: %w", delErr)
+ }
+ common.Error(fmt.Sprintf("go side, doc %s, DeleteIngestionTasksByDocIDs failed", doc.ID), delErr)
+ }
indexName := fmt.Sprintf("ragflow_%s", kb.TenantID)
if s.docEngine != nil {
exists, err := s.docEngine.ChunkStoreExists(context.Background(), indexName, doc.KbID)
diff --git a/internal/service/document/document_test.go b/internal/service/document/document_test.go
index 5b62bedfa8..06665a5086 100644
--- a/internal/service/document/document_test.go
+++ b/internal/service/document/document_test.go
@@ -603,7 +603,7 @@ func TestDeleteDocumentFull_Basic(t *testing.T) {
}
// Verify tasks deleted
- tasks, _ := dao.NewTaskDAO().GetAllTasks()
+ tasks, _ := dao.NewTaskDAO().GetAllTasks(ctx, db)
if len(tasks) != 0 {
t.Fatalf("expected 0 tasks, got %d", len(tasks))
}
@@ -1122,7 +1122,7 @@ func TestStartParseDocuments_EnqueuesIngestionTask(t *testing.T) {
t.Fatalf("ingestion task status = %q, want %q", ingestionTask.Status, common.CREATED)
}
- tasks, err := svc.taskDAO.GetByDocID("doc-1")
+ tasks, err := svc.taskDAO.GetByDocID(ctx, db, "doc-1")
if err != nil {
t.Fatalf("load legacy tasks: %v", err)
}
diff --git a/internal/service/memory_message_service.go b/internal/service/memory_message_service.go
index da7f55e67f..ac171ea89c 100644
--- a/internal/service/memory_message_service.go
+++ b/internal/service/memory_message_service.go
@@ -302,14 +302,14 @@ func embedAndSave(_ context.Context, _ *CreateMemoryResponse, _ map[string]any)
return ErrEmbedderNotWired
}
-func (s *MemoryMessageService) insertTask(_ context.Context, row map[string]any) error {
+func (s *MemoryMessageService) insertTask(ctx context.Context, row map[string]any) error {
if s == nil {
return errors.New("nil MemoryMessageService")
}
if s.taskDAO == nil {
s.taskDAO = dao.NewTaskDAO()
}
- return s.taskDAO.Create(taskFromRow(row))
+ return s.taskDAO.Create(ctx, dao.DB, taskFromRow(row))
}
// newUUIDString is a thin wrapper so we can swap in a real UUID
diff --git a/test/testcases/restful_api/test_chunks.py b/test/testcases/restful_api/test_chunks.py
index 6e31103c84..336621b524 100644
--- a/test/testcases/restful_api/test_chunks.py
+++ b/test/testcases/restful_api/test_chunks.py
@@ -281,7 +281,7 @@ def test_chunk_add_invalid_dataset_and_document_contract(rest_client, create_doc
assert invalid_document_res.status_code == 200
invalid_document_payload = invalid_document_res.json()
assert invalid_document_payload["code"] == 102, invalid_document_payload
- assert invalid_document_payload["message"] == f"You don't own the document {INVALID_ID_32}.", invalid_document_payload
+ assert invalid_document_payload["message"] == f"you don't own the document {INVALID_ID_32}", invalid_document_payload
@pytest.mark.p2
@@ -315,7 +315,7 @@ def test_chunk_add_repeated_and_deleted_document_contract(rest_client, create_do
assert add_after_delete_res.status_code == 200
add_after_delete_payload = add_after_delete_res.json()
assert add_after_delete_payload["code"] == 102, add_after_delete_payload
- assert add_after_delete_payload["message"] == f"You don't own the document {document_id}.", add_after_delete_payload
+ assert add_after_delete_payload["message"] == f"you don't own the document {document_id}", add_after_delete_payload
@pytest.mark.p2
@@ -446,7 +446,7 @@ def test_chunk_delete_partial_duplicate_repeat_and_invalid_target_contract(rest_
assert invalid_document_res.status_code == 200
invalid_document_payload = invalid_document_res.json()
assert invalid_document_payload["code"] == 102, invalid_document_payload
- assert invalid_document_payload["message"] == f"You don't own the document {INVALID_ID_32}.", invalid_document_payload
+ assert invalid_document_payload["message"] == f"you don't own the document {INVALID_ID_32}", invalid_document_payload
@pytest.mark.p2
@@ -560,7 +560,7 @@ def test_chunk_list_default_get_id_and_invalid_target_contract(rest_client, crea
assert invalid_document_res.status_code == 200
invalid_document_payload = invalid_document_res.json()
assert invalid_document_payload["code"] == 102, invalid_document_payload
- assert invalid_document_payload["message"] == f"You don't own the document {INVALID_ID_32}.", invalid_document_payload
+ assert invalid_document_payload["message"] == f"you don't own the document {INVALID_ID_32}", invalid_document_payload
@pytest.mark.p2
@@ -752,7 +752,7 @@ def test_chunk_update_invalid_target_and_param_contract(rest_client, create_docu
assert invalid_document_res.status_code == 200
invalid_document_payload = invalid_document_res.json()
assert invalid_document_payload["code"] == 102, invalid_document_payload
- assert invalid_document_payload["message"] == f"You don't own the document {INVALID_ID_32}.", invalid_document_payload
+ assert invalid_document_payload["message"] == f"you don't own the document {INVALID_ID_32}", invalid_document_payload
invalid_chunk_res = rest_client.patch(
f"{base_path}/{INVALID_ID_32}",
@@ -826,6 +826,6 @@ def test_chunk_update_repeated_concurrent_and_deleted_document_contract(rest_cli
update_after_delete_payload = update_after_delete.json()
assert update_after_delete_payload["code"] == 102, update_after_delete_payload
assert update_after_delete_payload["message"] in {
- f"You don't own the document {document_id}.",
+ f"you don't own the document {document_id}",
f"Can't find this chunk {chunk_id}",
}, update_after_delete_payload
diff --git a/test/testcases/restful_api/test_documents.py b/test/testcases/restful_api/test_documents.py
index 1572bbfd6d..1edad952b8 100644
--- a/test/testcases/restful_api/test_documents.py
+++ b/test/testcases/restful_api/test_documents.py
@@ -255,28 +255,28 @@ def test_documents_list_error_and_sorting_contract(rest_client, create_dataset,
f"/datasets/{dataset_id}/documents",
{"name": "unknown.txt"},
102,
- "You don't own the document unknown.txt.",
+ "you don't own the document unknown.txt",
),
(
"id unknown",
f"/datasets/{dataset_id}/documents",
{"id": "unknown.txt"},
102,
- "You don't own the document unknown.txt.",
+ "you don't own the document unknown.txt",
),
(
"name+id unknown name",
f"/datasets/{dataset_id}/documents",
{"id": first_id, "name": "unknown"},
102,
- "You don't own the document unknown.",
+ "you don't own the document unknown",
),
(
"name+id unknown id",
f"/datasets/{dataset_id}/documents",
{"id": "id", "name": "ragflow_test_upload_0.txt"},
102,
- "You don't own the document id.",
+ "you don't own the document id",
),
(
"run invalid",
diff --git a/test/testcases/test_http_api/test_chunk_management_within_dataset/test_add_chunk.py b/test/testcases/test_http_api/test_chunk_management_within_dataset/test_add_chunk.py
index ed0a0526b0..e6e450e746 100644
--- a/test/testcases/test_http_api/test_chunk_management_within_dataset/test_add_chunk.py
+++ b/test/testcases/test_http_api/test_chunk_management_within_dataset/test_add_chunk.py
@@ -202,7 +202,7 @@ class TestAddChunk:
(
INVALID_ID_32,
102,
- f"You don't own the document {INVALID_ID_32}.",
+ f"you don't own the document {INVALID_ID_32}",
),
],
)
@@ -242,7 +242,7 @@ class TestAddChunk:
delete_documents(HttpApiAuth, dataset_id, {"ids": [document_id]})
res = add_chunk(HttpApiAuth, dataset_id, document_id, {"content": "chunk test"})
assert res["code"] == 102
- assert res["message"] == f"You don't own the document {document_id}."
+ assert res["message"] == f"you don't own the document {document_id}"
@pytest.mark.skip(reason="issues/6411")
def test_concurrent_add_chunk(self, HttpApiAuth, add_document):
diff --git a/test/testcases/test_http_api/test_chunk_management_within_dataset/test_delete_chunks.py b/test/testcases/test_http_api/test_chunk_management_within_dataset/test_delete_chunks.py
index a645493387..c898cdd6d4 100644
--- a/test/testcases/test_http_api/test_chunk_management_within_dataset/test_delete_chunks.py
+++ b/test/testcases/test_http_api/test_chunk_management_within_dataset/test_delete_chunks.py
@@ -54,7 +54,7 @@ class TestChunksDeletion:
@pytest.mark.parametrize(
"document_id, expected_code, expected_message",
[
- (INVALID_ID_32, 102, f"You don't own the document {INVALID_ID_32}."),
+ (INVALID_ID_32, 102, f"you don't own the document {INVALID_ID_32}"),
],
)
def test_invalid_document_id(self, HttpApiAuth, add_chunks_func, document_id, expected_code, expected_message):
diff --git a/test/testcases/test_http_api/test_chunk_management_within_dataset/test_list_chunks.py b/test/testcases/test_http_api/test_chunk_management_within_dataset/test_list_chunks.py
index 198d83666a..6a66aac947 100644
--- a/test/testcases/test_http_api/test_chunk_management_within_dataset/test_list_chunks.py
+++ b/test/testcases/test_http_api/test_chunk_management_within_dataset/test_list_chunks.py
@@ -198,7 +198,7 @@ class TestChunksList:
(
INVALID_ID_32,
102,
- f"You don't own the document {INVALID_ID_32}.",
+ f"you don't own the document {INVALID_ID_32}",
),
],
)
diff --git a/test/testcases/test_http_api/test_chunk_management_within_dataset/test_update_chunk.py b/test/testcases/test_http_api/test_chunk_management_within_dataset/test_update_chunk.py
index ff862b2052..58664555cc 100644
--- a/test/testcases/test_http_api/test_chunk_management_within_dataset/test_update_chunk.py
+++ b/test/testcases/test_http_api/test_chunk_management_within_dataset/test_update_chunk.py
@@ -167,7 +167,7 @@ class TestUpdatedChunk:
(
INVALID_ID_32,
102,
- f"You don't own the document {INVALID_ID_32}.",
+ f"you don't own the document {INVALID_ID_32}",
),
],
)
@@ -247,4 +247,4 @@ class TestUpdatedChunk:
delete_documents(HttpApiAuth, dataset_id, {"ids": [document_id]})
res = update_chunk(HttpApiAuth, dataset_id, document_id, chunk_ids[0])
assert res["code"] == 102
- assert res["message"] in [f"You don't own the document {document_id}.", f"Can't find this chunk {chunk_ids[0]}"]
+ assert res["message"] in [f"you don't own the document {document_id}", f"Can't find this chunk {chunk_ids[0]}"]
diff --git a/test/testcases/test_http_api/test_file_management_within_dataset/test_list_documents.py b/test/testcases/test_http_api/test_file_management_within_dataset/test_list_documents.py
index af5b43c806..b71afa6415 100644
--- a/test/testcases/test_http_api/test_file_management_within_dataset/test_list_documents.py
+++ b/test/testcases/test_http_api/test_file_management_within_dataset/test_list_documents.py
@@ -242,7 +242,7 @@ class TestDocumentsList:
{"name": "unknown.txt"},
102,
0,
- "You don't own the document unknown.txt.",
+ "you don't own the document unknown.txt",
),
],
)
@@ -273,7 +273,7 @@ class TestDocumentsList:
(None, 0, 5, ""),
("", 0, 5, ""),
(lambda r: r[0], 0, 1, ""),
- ("unknown.txt", 102, 0, "You don't own the document unknown.txt."),
+ ("unknown.txt", 102, 0, "you don't own the document unknown.txt"),
],
)
def test_id(
@@ -308,13 +308,13 @@ class TestDocumentsList:
[
(lambda r: r[0], "ragflow_test_upload_0.txt", 0, 1, ""),
(lambda r: r[0], "ragflow_test_upload_1.txt", 0, 0, ""),
- (lambda r: r[0], "unknown", 102, 0, "You don't own the document unknown."),
+ (lambda r: r[0], "unknown", 102, 0, "you don't own the document unknown"),
(
"id",
"ragflow_test_upload_0.txt",
102,
0,
- "You don't own the document id.",
+ "you don't own the document id",
),
],
)
diff --git a/test/testcases/test_http_api/test_file_management_within_dataset/test_stop_parse_documents.py b/test/testcases/test_http_api/test_file_management_within_dataset/test_stop_parse_documents.py
index ab2a251560..c176964289 100644
--- a/test/testcases/test_http_api/test_file_management_within_dataset/test_stop_parse_documents.py
+++ b/test/testcases/test_http_api/test_file_management_within_dataset/test_stop_parse_documents.py
@@ -69,8 +69,8 @@ class TestDocumentsParseStop:
[
pytest.param(None, 102, """AttributeError("\'NoneType\' object has no attribute \'get\'")""", marks=pytest.mark.skip),
pytest.param({"document_ids": []}, 102, "`document_ids` is required", marks=pytest.mark.p1),
- pytest.param({"document_ids": ["invalid_id"]}, 102, "You don't own the document invalid_id.", marks=pytest.mark.p3),
- pytest.param({"document_ids": ["\n!?。;!?\"'"]}, 102, """You don\'t own the document \n!?。;!?"\'.""", marks=pytest.mark.p3),
+ pytest.param({"document_ids": ["invalid_id"]}, 102, "you don't own the document invalid_id", marks=pytest.mark.p3),
+ pytest.param({"document_ids": ["\n!?。;!?\"'"]}, 102, """you don\'t own the document \n!?。;!?"\'""", marks=pytest.mark.p3),
pytest.param("not json", 102, "AttributeError(\"'str' object has no attribute 'get'\")", marks=pytest.mark.skip),
pytest.param(lambda r: {"document_ids": r[:1]}, 0, "", marks=pytest.mark.p1),
pytest.param(lambda r: {"document_ids": r}, 0, "", marks=pytest.mark.p1),
@@ -144,7 +144,7 @@ class TestDocumentsParseStop:
payload = payload(document_ids)
res = stop_parse_documents(HttpApiAuth, dataset_id, payload)
assert res["code"] == 102
- assert res["message"] == "You don't own the document invalid_id."
+ assert res["message"] == "you don't own the document invalid_id"
validate_document_parse_cancel(HttpApiAuth, dataset_id, document_ids)
diff --git a/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_add_chunk.py b/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_add_chunk.py
index 97c1274484..2db1022752 100644
--- a/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_add_chunk.py
+++ b/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_add_chunk.py
@@ -170,7 +170,7 @@ class TestAddChunk:
with pytest.raises(Exception) as exception_info:
document.add_chunk(content="chunk test")
- assert f"You don't own the document {document.id}" in str(exception_info.value), str(exception_info.value)
+ assert f"you don't own the document {document.id}" in str(exception_info.value), str(exception_info.value)
@pytest.mark.skip(reason="issues/6411")
@pytest.mark.p3
diff --git a/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_update_chunk.py b/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_update_chunk.py
index a93a1a72d3..b6fef1350b 100644
--- a/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_update_chunk.py
+++ b/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_update_chunk.py
@@ -167,5 +167,5 @@ class TestUpdatedChunk:
with pytest.raises(Exception) as exception_info:
chunks[0].update({})
message = str(exception_info.value)
- ownership_message = f"You don't own the document {chunks[0].document_id}"
+ ownership_message = f"you don't own the document {chunks[0].document_id}"
assert message.rstrip(".") == ownership_message or message == f"Can't find this chunk {chunks[0].id}", message
diff --git a/test/testcases/test_sdk_api/test_file_management_within_dataset/test_list_documents.py b/test/testcases/test_sdk_api/test_file_management_within_dataset/test_list_documents.py
index e77912628c..5e9b6c2623 100644
--- a/test/testcases/test_sdk_api/test_file_management_within_dataset/test_list_documents.py
+++ b/test/testcases/test_sdk_api/test_file_management_within_dataset/test_list_documents.py
@@ -158,7 +158,7 @@ class TestDocumentsList:
({"name": None}, 5, ""),
({"name": ""}, 5, ""),
({"name": "ragflow_test_upload_0.txt"}, 1, ""),
- ({"name": "unknown.txt"}, 0, "You don't own the document unknown.txt"),
+ ({"name": "unknown.txt"}, 0, "you don't own the document unknown.txt"),
],
)
def test_name(self, add_documents, params, expected_num, expected_message):
@@ -180,7 +180,7 @@ class TestDocumentsList:
(None, 5, ""),
("", 5, ""),
(lambda docs: docs[0].id, 1, ""),
- ("unknown.txt", 0, "You don't own the document unknown.txt"),
+ ("unknown.txt", 0, "you don't own the document unknown.txt"),
],
)
def test_id(self, add_documents, document_id, expected_num, expected_message):
@@ -206,8 +206,8 @@ class TestDocumentsList:
[
(lambda docs: docs[0].id, "ragflow_test_upload_0.txt", 1, ""),
(lambda docs: docs[0].id, "ragflow_test_upload_1.txt", 0, ""),
- (lambda docs: docs[0].id, "unknown", 0, "You don't own the document unknown"),
- ("invalid_id", "ragflow_test_upload_0.txt", 0, "You don't own the document invalid_id"),
+ (lambda docs: docs[0].id, "unknown", 0, "you don't own the document unknown"),
+ ("invalid_id", "ragflow_test_upload_0.txt", 0, "you don't own the document invalid_id"),
],
)
def test_name_and_id(self, add_documents, document_id, name, expected_num, expected_message):
diff --git a/test/testcases/test_web_api/test_chunk_app/test_chunk_routes_unit.py b/test/testcases/test_web_api/test_chunk_app/test_chunk_routes_unit.py
index d7bdcfca06..5a2f2aee4b 100644
--- a/test/testcases/test_web_api/test_chunk_app/test_chunk_routes_unit.py
+++ b/test/testcases/test_web_api/test_chunk_app/test_chunk_routes_unit.py
@@ -598,7 +598,7 @@ def test_restful_chunk_guard_branches_unit(monkeypatch):
monkeypatch.setattr(module.KnowledgebaseService, "accessible", lambda **_kwargs: True)
monkeypatch.setattr(module.DocumentService, "query", lambda **_kwargs: [])
res = _run(_route_core(module.list_chunks)("tenant-1", "kb-1", "doc-1"))
- assert res["message"] == "You don't own the document doc-1.", res
+ assert res["message"] == "you don't own the document doc-1", res
monkeypatch.setattr(module.DocumentService, "query", lambda **_kwargs: [_DummyDoc()])
module.request = SimpleNamespace(args={"id": "chunk-1"}, headers={})
diff --git a/test/testcases/test_web_api/test_chunk_app/test_create_chunk.py b/test/testcases/test_web_api/test_chunk_app/test_create_chunk.py
index f796cac943..bc236229d8 100644
--- a/test/testcases/test_web_api/test_chunk_app/test_create_chunk.py
+++ b/test/testcases/test_web_api/test_chunk_app/test_create_chunk.py
@@ -145,7 +145,7 @@ class TestAddChunk:
@pytest.mark.parametrize(
"document_id, expected_code, expected_message",
[
- ("invalid_document_id", 102, "You don't own the document invalid_document_id."),
+ ("invalid_document_id", 102, "you don't own the document invalid_document_id"),
],
)
def test_invalid_document_id(self, WebApiAuth, add_document, document_id, expected_code, expected_message):
@@ -177,7 +177,7 @@ class TestAddChunk:
delete_document(WebApiAuth, dataset_id, {"ids": [document_id]})
res = add_chunk(WebApiAuth, dataset_id, document_id, {"content": "chunk test"})
assert res["code"] == 102, res
- assert res["message"] == f"You don't own the document {document_id}.", res
+ assert res["message"] == f"you don't own the document {document_id}", res
@pytest.mark.skip(reason="issues/6411")
@pytest.mark.p3
diff --git a/test/testcases/test_web_api/test_chunk_app/test_update_chunk.py b/test/testcases/test_web_api/test_chunk_app/test_update_chunk.py
index e94fc9b180..bfe99a40b1 100644
--- a/test/testcases/test_web_api/test_chunk_app/test_update_chunk.py
+++ b/test/testcases/test_web_api/test_chunk_app/test_update_chunk.py
@@ -156,7 +156,7 @@ class TestUpdateChunk:
@pytest.mark.parametrize(
"document_id, expected_code, expected_message",
[
- ("invalid_doc_id", 102, "You don't own the document invalid_doc_id."),
+ ("invalid_doc_id", 102, "you don't own the document invalid_doc_id"),
],
)
def test_invalid_document_id_for_update(self, WebApiAuth, add_chunks, document_id, expected_code, expected_message):
@@ -217,4 +217,4 @@ class TestUpdateChunk:
delete_document(WebApiAuth, dataset_id, {"ids": [document_id]})
res = update_chunk(WebApiAuth, dataset_id, document_id, chunk_ids[0], {"content": "test content"})
assert res["code"] == 102, res
- assert res["message"] in [f"You don't own the document {document_id}.", f"Can't find this chunk {chunk_ids[0]}"]
+ assert res["message"] in [f"you don't own the document {document_id}", f"Can't find this chunk {chunk_ids[0]}"]
diff --git a/test/testcases/test_web_api/test_document_app/test_list_documents.py b/test/testcases/test_web_api/test_document_app/test_list_documents.py
index 9ace9185ed..b3452a8a7c 100644
--- a/test/testcases/test_web_api/test_document_app/test_list_documents.py
+++ b/test/testcases/test_web_api/test_document_app/test_list_documents.py
@@ -197,7 +197,7 @@ class TestDocumentsList:
# Use a non-existent document ID
res = list_documents(WebApiAuth, {"kb_id": kb_id, "id": "non_existent_doc_id"})
assert res["code"] == 102
- assert "You don't own the document" in res["message"]
+ assert "you don't own the document" in res["message"]
@pytest.mark.p3
def test_create_time_filter(self, WebApiAuth, add_documents):