mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-03 22:30:31 +08:00
Refa: empty ids means no-op operation (#13439)
### What problem does this PR solve? Empty ids means no-op operation. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [x] Documentation Update - [x] Refactoring --------- Co-authored-by: writinwaters <cai.keith@gmail.com>
This commit is contained in:
@@ -673,6 +673,20 @@ def test_rm_chunk_delete_exception_partial_compensation_and_cleanup_unit(monkeyp
|
||||
res = _run(module.rm())
|
||||
assert res["message"] == "Document not found!", res
|
||||
|
||||
_set_request_json(monkeypatch, module, {"doc_id": "doc-1", "chunk_ids": []})
|
||||
monkeypatch.setattr(
|
||||
module.DocumentService,
|
||||
"get_by_id",
|
||||
lambda _doc_id: (_ for _ in ()).throw(AssertionError("get_by_id must not run for empty delete payload")),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
module.settings.docStoreConn,
|
||||
"delete",
|
||||
lambda *_args, **_kwargs: (_ for _ in ()).throw(AssertionError("delete must not run for empty delete payload")),
|
||||
)
|
||||
res = _run(module.rm())
|
||||
assert res["code"] == 0, res
|
||||
|
||||
monkeypatch.setattr(module.DocumentService, "get_by_id", lambda _doc_id: (True, _DummyDoc()))
|
||||
|
||||
def _raise_delete(*_args, **_kwargs):
|
||||
|
||||
@@ -165,7 +165,7 @@ class TestChunksDeletion:
|
||||
pytest.param("not json", 100, """UnboundLocalError("local variable \'duplicate_messages\' referenced before assignment")""", 5, marks=pytest.mark.skip(reason="pull/6376")),
|
||||
pytest.param(lambda r: {"chunk_ids": r[:1]}, 0, "", 3, marks=pytest.mark.p3),
|
||||
pytest.param(lambda r: {"chunk_ids": r}, 0, "", 0, marks=pytest.mark.p1),
|
||||
pytest.param({"chunk_ids": []}, 0, "", 0, marks=pytest.mark.p3),
|
||||
pytest.param({"chunk_ids": []}, 0, "", 5, marks=pytest.mark.p3),
|
||||
],
|
||||
)
|
||||
def test_basic_scenarios(self, WebApiAuth, add_chunks_func, payload, expected_code, expected_message, remaining):
|
||||
|
||||
@@ -472,14 +472,8 @@ def test_delete_route_error_summary_matrix_unit(monkeypatch):
|
||||
assert res["data"]["errors"], res
|
||||
|
||||
req_state["ids"] = None
|
||||
monkeypatch.setattr(
|
||||
module.KnowledgebaseService,
|
||||
"query",
|
||||
lambda **_kwargs: (_ for _ in ()).throw(module.OperationalError("db down")),
|
||||
)
|
||||
res = _run(inspect.unwrap(module.delete)("tenant-1"))
|
||||
assert res["code"] == module.RetCode.DATA_ERROR, res
|
||||
assert res["message"] == "Database operation failed", res
|
||||
assert res["code"] == module.RetCode.SUCCESS, res
|
||||
|
||||
|
||||
@pytest.mark.p2
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
import pytest
|
||||
from common import batch_create_datasets
|
||||
from common import batch_create_datasets, list_kbs, rm_kb
|
||||
from libs.auth import RAGFlowWebApiAuth
|
||||
from pytest import FixtureRequest
|
||||
from ragflow_sdk import RAGFlow
|
||||
@@ -22,17 +22,31 @@ from ragflow_sdk import RAGFlow
|
||||
|
||||
@pytest.fixture(scope="class")
|
||||
def add_datasets(request: FixtureRequest, client: RAGFlow, WebApiAuth: RAGFlowWebApiAuth) -> list[str]:
|
||||
dataset_ids = batch_create_datasets(WebApiAuth, 5)
|
||||
|
||||
def cleanup():
|
||||
client.delete_datasets(ids=None)
|
||||
# Web KB cleanup cannot call SDK dataset bulk delete with empty ids; deletion must stay explicit.
|
||||
res = list_kbs(WebApiAuth, params={"page_size": 1000})
|
||||
existing_ids = {kb["id"] for kb in res["data"]["kbs"]}
|
||||
for dataset_id in dataset_ids:
|
||||
if dataset_id in existing_ids:
|
||||
rm_kb(WebApiAuth, {"kb_id": dataset_id})
|
||||
|
||||
request.addfinalizer(cleanup)
|
||||
return batch_create_datasets(WebApiAuth, 5)
|
||||
return dataset_ids
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def add_datasets_func(request: FixtureRequest, client: RAGFlow, WebApiAuth: RAGFlowWebApiAuth) -> list[str]:
|
||||
dataset_ids = batch_create_datasets(WebApiAuth, 3)
|
||||
|
||||
def cleanup():
|
||||
client.delete_datasets(ids=None)
|
||||
# Web KB cleanup cannot call SDK dataset bulk delete with empty ids; deletion must stay explicit.
|
||||
res = list_kbs(WebApiAuth, params={"page_size": 1000})
|
||||
existing_ids = {kb["id"] for kb in res["data"]["kbs"]}
|
||||
for dataset_id in dataset_ids:
|
||||
if dataset_id in existing_ids:
|
||||
rm_kb(WebApiAuth, {"kb_id": dataset_id})
|
||||
|
||||
request.addfinalizer(cleanup)
|
||||
return batch_create_datasets(WebApiAuth, 3)
|
||||
return dataset_ids
|
||||
|
||||
Reference in New Issue
Block a user