{"record":{"id":"f48475e492696ae5","repo":"langchain-ai/langchain","slug":"unsupported-operand-type-s-for-type-self-f48475","errorCode":null,"errorMessage":"unsupported operand type(s) for +: '{type(self)}' and '{type(other)}'","messagePattern":"unsupported operand type\\(s\\) for \\+: '(.+?)' and '(.+?)'","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/tracers/log_stream.py","lineNumber":154,"sourceCode":"    def __add__(self, other: RunLogPatch | Any) -> RunLog:\n        \"\"\"Combine two `RunLogPatch` instances.\n\n        Args:\n            other: The other `RunLogPatch` to combine with.\n\n        Raises:\n            TypeError: If the other object is not a `RunLogPatch`.\n\n        Returns:\n            A new `RunLog` representing the combination of the two.\n        \"\"\"\n        if type(other) is RunLogPatch:\n            ops = self.ops + other.ops\n            state = jsonpatch.apply_patch(None, copy.deepcopy(ops))\n            return RunLog(*ops, state=state)\n\n        msg = f\"unsupported operand type(s) for +: '{type(self)}' and '{type(other)}'\"\n        raise TypeError(msg)\n\n    @override\n    def __repr__(self) -> str:\n        # 1:-1 to get rid of the [] around the list\n        return f\"RunLogPatch({pformat(self.ops)[1:-1]})\"\n\n    @override\n    def __eq__(self, other: object) -> bool:\n        return isinstance(other, RunLogPatch) and self.ops == other.ops\n\n    __hash__ = None  # type: ignore[assignment]\n\n\nclass RunLog(RunLogPatch):\n    \"\"\"Run log.\"\"\"\n\n    state: RunState\n    \"\"\"Current state of the log, obtained from applying all ops in sequence.\"\"\"","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/tracers/log_stream.py#L136-L172","documentation":"Raised by RunLogPatch.__add__ when the right operand is not exactly a RunLogPatch. RunLogPatch objects accumulate JSON-patch ops and only support addition with their own kind; anything else (str, list, dict, RunLog) is a type error mirroring Python's built-in + semantics. The message reproduces the standard 'unsupported operand type(s)' wording with the concrete types.","triggerScenarios":"runnables stream logs via astream_log and caller code does patch + some_dict, patch + list_of_ops, or patch + run_log expecting concatenation; storing patches and accidentally adding a serialized ops list back; mixing RunLog and RunLogPatch in a reduction with functools.reduce over a heterogeneous list.","commonSituations":"Reducing streamed RunLogPatch chunks with a wrong initial value (e.g. [] instead of the first patch); assuming RunLogPatch behaves like a plain list of ops; tutorial code that adds the final RunLog back onto patches.","solutions":["Only combine RunLogPatch with RunLogPatch: total = patches[0]; for p in patches[1:]: total = total + p","Use functools.reduce(operator.add, patches, patches[0]) with no foreign initial value","To add a RunLog and a patch, put the RunLog on the left: run_log + run_log_patch (RunLog.__add__ handles that direction)","Inspect types before adding when consuming astream_log programmatically"],"exampleFix":"# before\nfrom functools import reduce\nimport operator\nstate = reduce(operator.add, patches, [])  # [] is not a RunLogPatch\n# after\nstate = reduce(operator.add, patches)  # patches are all RunLogPatch; first is the seed","handlingStrategy":"type-guard","validationCode":"from langchain_core.tracers.log_stream import RunLogPatch\nassert all(type(p) is RunLogPatch for p in patches), [type(p) for p in patches]","typeGuard":"from langchain_core.tracers.log_stream import RunLogPatch\nfrom typing import Any\n\ndef is_run_log_patch(x: Any) -> bool:\n    return type(x) is RunLogPatch","tryCatchPattern":null,"preventionTips":["Reduce patches only among themselves; never seed with [] or a foreign type","Keep streamed objects as-is — do not extract .ops for aggregation","Remember RunLog + RunLogPatch is legal, RunLogPatch + anything-else is not"],"tags":["streaming","astream-log","type-error","python"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}