{"record":{"id":"a3599d3b8661212d","repo":"docling-project/docling","slug":"path-or-stream-must-be-path-or-bytesio","errorCode":null,"errorMessage":"path_or_stream must be Path or BytesIO","messagePattern":"path_or_stream must be Path or BytesIO","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"docling/backend/xml/xbrl_backend.py","lineNumber":148,"sourceCode":"                    )\n                    zip_paths = [\n                        str(item)\n                        for item in taxonomy_path.iterdir()\n                        if item.is_file()\n                        and item.suffix.lower() == \".zip\"\n                        and zipfile.is_zipfile(item)\n                    ]\n                    if zip_paths:\n                        _log.debug(\n                            f\"Files to be passed as taxonomy packages: {zip_paths}\"\n                        )\n                if isinstance(path_or_stream, BytesIO):\n                    instance_path: Path = tmp_path / \"instance.xml\"\n                    instance_path.write_bytes(path_or_stream.getvalue())\n                elif isinstance(path_or_stream, Path):\n                    instance_path = Path(shutil.copy2(path_or_stream, tmp_path))\n                else:\n                    raise TypeError(\"path_or_stream must be Path or BytesIO\")\n\n                # cntlr = Cntlr.Cntlr(logFileName=\"logToPrint\")\n                cntlr = Cntlr.Cntlr()\n                # Disable remote access for security purposes, unless explicitly set\n                if not self.options.enable_remote_fetch:\n                    cntlr.webCache.workOffline = True\n                    cntlr.modelManager.validateDisclosureSystem = False\n                else:\n                    # TODO: parametrize the timeout?\n                    cntlr.webCache.timeout = _WEB_CACHE_TIMEOUT\n                    # TODO: custom set cntlr.webCache.cacheDir?\n                    _log.debug(\n                        f\"Web Cache for remote taxonomy is: {cntlr.webCache.cacheDir}\"\n                    )\n\n                model = cntlr.modelManager.load(\n                    str(instance_path), taxonomyPackages=zip_paths\n                )","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/backend/xml/xbrl_backend.py#L130-L166","documentation":"The XBRL backend only handles pathlib.Path (file to copy into its temp workspace) or io.BytesIO (bytes to write as instance.xml) as path_or_stream; any other object — str path, open file handle, other stream types — hits the else branch and raises TypeError with this message.","triggerScenarios":"Constructing XBRLBackend (or converting XBRL via a custom pipeline) with a str filename, an io.TextIOWrapper, or any stream class other than BytesIO as the source.","commonSituations":"Passing \"report.xbrl\" as a string; forwarding an already-open file from caller code; wrappers that expose SpooledTemporaryFile or request bodies.","solutions":["Wrap strings: pass Path(source) instead of source.","For streams, pass BytesIO(raw_bytes); read and encode text content first.","Type-check your source before calling: isinstance(src, (Path, BytesIO)).","Use DocumentConverter.convert(), which normalizes accepted source types."],"exampleFix":"# before\nresult = converter.convert(\"report.xbrl\")  # str reaches backend -> TypeError\n\n# after\nfrom pathlib import Path\nresult = converter.convert(Path(\"report.xbrl\"))","handlingStrategy":"type-guard","validationCode":"from pathlib import Path\nfrom io import BytesIO\n\ndef acceptable_source(src) -> bool:\n    return isinstance(src, (Path, BytesIO))","typeGuard":"from pathlib import Path\nfrom io import BytesIO\nfrom typing import TypeGuard, Union\n\ndef is_backend_source(src: object) -> TypeGuard[Union[Path, BytesIO]]:\n    return isinstance(src, (Path, BytesIO))","tryCatchPattern":"try:\n    backend = XBRLBackend(in_doc, src, opts)\nexcept TypeError as e:\n    if \"Path or BytesIO\" in str(e):\n        src = Path(src) if isinstance(src, str) else BytesIO(src.read())\n        backend = XBRLBackend(in_doc, src, opts)\n    else:\n        raise","preventionTips":["Coerce str sources to Path at your pipeline entry point.","Use BytesIO for in-memory sources; other stream types are rejected.","Route conversions through DocumentConverter to get source normalization."],"tags":["xbrl","type-error","api-misuse","pathlib","bytesio"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}