{"record":{"id":"7bcdf50b60b7c8a1","repo":"RyanCodrai/turbovec","slug":"ids-pos-is-id-r-of-type-type-id-name","errorCode":null,"errorMessage":"ids[{pos}] is {id_!r} of type {type(id_).__name__}; ids must be str (or None for a generated UUID). Non-str ids are rejected because JSON persistence coerces keys to str, silently colliding with any equal-looking str id (e.g. 2 vs '2') on dump/load.","messagePattern":"ids\\[(.+?)\\] is (.+?) of type (.+?); ids must be str \\(or None for a generated UUID\\)\\. Non-str ids are rejected because JSON persistence coerces keys to str, silently colliding with any equal-looking str id \\(e\\.g\\. 2 vs '2'\\) on dump/load\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"turbovec-python/python/turbovec/langchain.py","lineNumber":249,"sourceCode":"        Any other non-``str`` id raises ``TypeError``. This is a\n        deliberate deviation from the reference InMemoryVectorStore,\n        which accepts e.g. an ``int`` id and then corrupts it: JSON\n        persistence coerces every key to ``str``, so ``2`` and ``\"2\"``\n        are two documents in memory but collapse to one on ``dump``/\n        ``load`` — silent data loss plus an out-of-sync side-car.\n        Rejecting at the add boundary (the declared contract is\n        ``list[str]``) makes that state unrepresentable. ``bool`` is a\n        subclass of ``int`` and is rejected like any other non-str type:\n        only ``str`` instances (and ``None``) are accepted.\n        \"\"\"\n        normalized: list[str] = []\n        for pos, id_ in enumerate(ids):\n            if id_ is None:\n                normalized.append(str(uuid.uuid4()))\n            elif isinstance(id_, str):\n                normalized.append(id_)\n            else:\n                raise TypeError(\n                    f\"ids[{pos}] is {id_!r} of type {type(id_).__name__}; \"\n                    \"ids must be str (or None for a generated UUID). \"\n                    \"Non-str ids are rejected because JSON persistence \"\n                    \"coerces keys to str, silently colliding with any \"\n                    \"equal-looking str id (e.g. 2 vs '2') on dump/load.\"\n                )\n        return normalized\n\n    def add_texts(\n        self,\n        texts: Iterable[str],\n        metadatas: list[dict] | None = None,\n        ids: list[str] | None = None,\n        **_: Any,\n    ) -> list[str]:\n        texts_list = list(texts)\n        if not texts_list:\n            return []","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/RyanCodrai/turbovec/blob/ccab9f325e6ce2a270a87daf01ae4e443bcf2d49/turbovec-python/python/turbovec/langchain.py#L231-L267","documentation":"TypeError raised in _normalize_ids (from add_texts/aadd_texts) when an id is neither str nor None — e.g. int, bool (a subclass of int). Deliberately stricter than the reference InMemoryVectorStore: JSON persistence coerces dict keys to str, so an int id 2 would silently collide with the str id '2' on dump/load, corrupting the store.","triggerScenarios":"Thrown at turbovec-python/python/turbovec/langchain.py:249 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass str ids (or None to get a generated UUID): ids=['2'] instead of ids=[2].","Convert caller-supplied ids with str(id) at the boundary — but only when no int/str collision is possible.","Catch the TypeError in ingestion code to reject non-str id schemes up front."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ccab9f325e6ce2a270a87daf01ae4e443bcf2d49","analyzedAt":"2026-09-06T08:39:18.516Z","contentChangedAt":"2026-09-06T08:39:18.516Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}