{"record":{"id":"7d28dedd3cfdd289","repo":"TencentCloud/TencentDB-Agent-Memory","slug":"service-id-must-be-provided-7d28de","errorCode":null,"errorMessage":"service_id must be provided","messagePattern":"service_id must be provided","errorType":"validation","errorClass":"ParamError","httpStatus":null,"severity":"error","filePath":"sdk/memory-core/python/tencentdb_agent_memory/v3/client.py","lineNumber":189,"sourceCode":"        api_key: str = \"\",\n        service_id: Optional[str] = None,\n        *,\n        team_id: str = \"\",\n        agent_id: str = \"\",\n        user_id: str = \"\",\n        session_id: Optional[str] = None,\n        task_id: Optional[str] = None,\n        user_key: Optional[str] = None,\n        timeout: float = 30,\n        verify: bool = True,\n        stub: Optional[Stub] = None,\n    ) -> None:\n        _validate_construction(team_id, agent_id, user_id)\n        if stub is not None:\n            self._stub = stub\n        else:\n            if not service_id:\n                raise ParamError(\"service_id must be provided\")\n            # user_key 可选：内核不做用户级鉴权，但前置网关/面板可能需要\n            # 调用方身份，这里保持与 MetadataClient 一致的透传能力。\n            self._stub = HttpStub(\n                endpoint, api_key, service_id,\n                timeout=timeout, verify=verify, user_key=user_key,\n            )\n        self._iso = _IsolationCtx(team_id, agent_id, user_id, session_id, task_id)\n\n    # -- isolation overrides ------------------------------------------------\n\n    def with_isolation(\n        self,\n        *,\n        team_id: Optional[str] = None,\n        agent_id: Optional[str] = None,\n        user_id: Optional[str] = None,\n        session_id: Any = _UNSET,\n        task_id: Any = _UNSET,","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/3efcd317b84146d6a08518ac0f7ee7c8a8d200ec/sdk/memory-core/python/tencentdb_agent_memory/v3/client.py#L171-L207","documentation":"MemoryClient.__init__ only builds an HttpStub when no stub is injected; in that path service_id is mandatory because it identifies the service consumed by the gateway. A missing/empty service_id raises ParamError before any connection is attempted.","triggerScenarios":"Constructing MemoryClient without service_id (or with empty string) while leaving stub=None (the default); building a client from partial config where service_id was dropped.","commonSituations":"Env var for service_id unset; confusing service_id with api_key or team_id; code copied from tests that inject a stub, run in production without one.","solutions":["Pass a non-empty service_id to the constructor","Load it from config/env with a startup check (fail fast if blank)","For unit tests, inject a stub=... explicitly so service_id is not required","Verify you are not confusing service_id with team_id/agent_id"],"exampleFix":"// before\nclient = MemoryClient(endpoint=ep, api_key=key, service_id=os.getenv(\"SVC\", \"\"), ...)\n// after\nservice_id = os.environ[\"SERVICE_ID\"]\nclient = MemoryClient(endpoint=ep, api_key=key, service_id=service_id, ...)","handlingStrategy":"validation","validationCode":"if not service_id:\n    raise ValueError(\"service_id must be set before building MemoryClient\")","typeGuard":null,"tryCatchPattern":"try:\n    client = MemoryClient(...)\nexcept ParamError as e:\n    if \"service_id\" in str(e):\n        service_id = prompt_or_env(\"SERVICE_ID\")\n        client = MemoryClient(..., service_id=service_id)","preventionTips":["Load service_id from env with os.environ[...] so absence fails loudly","Validate the full client config (endpoint, api_key, service_id) at startup","Use different config templates for tests (stub-injected) vs production","Never default service_id to empty string"],"tags":["python","configuration","validation"],"backgroundTag":"missing-required-config","analyzedSha":"3efcd317b84146d6a08518ac0f7ee7c8a8d200ec","analyzedAt":"2026-09-01T05:44:22.276Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}