{"record":{"id":"7fe3fc4e31e09573","repo":"TencentCloud/TencentDB-Agent-Memory","slug":"delete-conversation-requires-message-ids-or-sessio","errorCode":null,"errorMessage":"delete_conversation requires message_ids or session_ids (the constructor session_id is intentionally NOT used for deletes)","messagePattern":"delete_conversation requires message_ids or session_ids \\(the constructor session_id is intentionally NOT used for deletes\\)","errorType":"validation","errorClass":"ParamError","httpStatus":null,"severity":"error","filePath":"sdk/memory-core/python/tencentdb_agent_memory/v3/client.py","lineNumber":319,"sourceCode":"        操作，若像读接口那样自动带上默认 session，只想按 message_ids 删几条\n        的调用方会意外把整个会话删掉。要删会话必须显式传 ``session_ids``。\n\n        ``session_id``（单数）已废弃，保留仅为兼容旧调用方，会合并进\n        ``session_ids``。\n        \"\"\"\n        normalized_messages = _normalize_delete_ids(\"message_ids\", message_ids, 5000)\n        normalized_sessions = _normalize_delete_ids(\"session_ids\", session_ids, 100)\n\n        if session_id is not None:\n            if not isinstance(session_id, str) or not session_id.strip():\n                raise ParamError(\"session_id must be a non-empty string\")\n            merged = list(normalized_sessions or [])\n            if session_id.strip() not in merged:\n                merged.append(session_id.strip())\n            normalized_sessions = merged\n\n        if not normalized_messages and not normalized_sessions:\n            raise ParamError(\n                \"delete_conversation requires message_ids or session_ids \"\n                \"(the constructor session_id is intentionally NOT used for deletes)\"\n            )\n\n        return self._stub.post(\n            f\"{_V3}/conversation/delete\",\n            _strip_none({\n                **self._iso.base_body(),\n                \"message_ids\": normalized_messages,\n                \"session_ids\": normalized_sessions,\n            }),\n        )\n\n    def count_conversation(\n        self,\n        *,\n        session_id: Optional[str] = None,\n        time_start: Optional[str] = None,","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/3efcd317b84146d6a08518ac0f7ee7c8a8d200ec/sdk/memory-core/python/tencentdb_agent_memory/v3/client.py#L301-L337","documentation":"delete_conversation requires explicit targeting via message_ids or session_ids; the constructor-level session_id is deliberately ignored for deletes to prevent accidental wide deletes based on ambient client state. Calling it with neither list raises ParamError.","triggerScenarios":"delete_conversation() with no arguments, relying on the session_id given at construction; calling with message_ids=None and session_ids=None (or empty lists) and no session_id parameter.","commonSituations":"Assuming the client's constructor session_id scopes deletes like it scopes add_conversation; generic wrapper code that forwards no filter arguments; scripts intending to 'wipe the current session' without passing it explicitly.","solutions":["Pass message_ids=[...] or session_ids=[...] (or session_id=...) explicitly on the call","If you want constructor-session deletes, pass it again: delete_conversation(session_id=client.session_id)","Batch by grouping message_ids (≤5000) or session_ids (≤100) per call","Never rely on ambient client state for destructive operations — this is by design"],"exampleFix":"// before\nclient.delete_conversation()  # relies on constructor session_id — raises\n// after\nclient.delete_conversation(session_ids=[client.session_id])","handlingStrategy":"validation","validationCode":"def can_delete(message_ids, session_ids, session_id=None):\n    has_msgs = bool(message_ids)\n    has_sessions = bool(session_ids) or (isinstance(session_id, str) and session_id.strip())\n    return has_msgs or has_sessions","typeGuard":null,"tryCatchPattern":"try:\n    client.delete_conversation()\nexcept ParamError as e:\n    if \"requires message_ids or session_ids\" in str(e):\n        client.delete_conversation(session_ids=[explicit_session])","preventionTips":["Never rely on constructor state for destructive calls — pass filters explicitly","Wrap delete_conversation in your own function that requires a target argument","Lint/review for zero-argument delete calls","Document that constructor session_id is write-scoped only"],"tags":["python","validation","destructive-operation"],"backgroundTag":"missing-required-argument","analyzedSha":"3efcd317b84146d6a08518ac0f7ee7c8a8d200ec","analyzedAt":"2026-09-01T05:44:22.276Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}