You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MetadataRouter.from_dict mutates the caller's serialized configuration #13420
MetadataRouter.from_dict() mutates the serialized dictionary supplied by the caller when output_type is present.
During the first deserialization, the serialized output_type string inside data["init_parameters"] is replaced with a live Python type. Reusing the same serialized dictionary in a second MetadataRouter.from_dict() call then fails because deserialize_type() receives an already-deserialized object instead of a string.
Error message
TypeError: can only concatenate str (not "types.GenericAlias") to str
from its serialized string representation into a Python generic type.
The second call fails with a TypeError.
Expected behavior
MetadataRouter.from_dict() should not mutate the caller-owned serialized dictionary.
The same serialized configuration should remain reusable across repeated deserialization calls.
Additional context
A similar caller-mutation issue was previously corrected for ConditionalRouter.from_dict() and BranchJoiner.from_dict() in PR #12935.
I reproduced this against current main. I have also prepared a focused regression test and minimal fix and would like to submit the corresponding pull request.
FAQ Check
I reproduced the issue against current main.
I searched existing issues and pull requests and did not find an exact report or active implementation.
I reproduced this on macOS / Python 3.11 at 76fc2d3. It doesn't seem specific to MetadataRouter: I ran to_dict() → from_dict(d) → from_dict(d) across components, and the input dict was mutated (and the second call failed) for ListJoiner, InMemoryBM25Retriever, InMemoryEmbeddingRetriever, DocumentWriter, ChatPromptBuilder, MockChatGenerator, DocumentSplitter, DocumentPreprocessor, PyPDFToDocument, PDFMinerToDocument, DOCXToDocument, OpenAIChatGenerator, Agent, FaithfulnessEvaluator, LLMEvaluator, Tool and SuperComponent. Only BranchJoiner (fixed in #12935) leaves its input unchanged. Pipeline.from_dict() is not affected, so this hits direct component-level from_dict() calls and nested deserialization.
Would maintainers prefer per-component fixes like #12935, or a shared approach (e.g. shallow-copying init_parameters before the *_inplace helpers)? Happy to help with follow-up PRs once #13421 lands, so as not to conflict with it.
Thanks for testing this across the wider component set. That confirms the caller-mutation pattern extends beyond the MetadataRouter-specific case reported here.
I kept #13421 intentionally scoped to MetadataRouter so the regression test and behavior change remain focused. I’ll wait for maintainer guidance on whether the preferred direction is to merge this narrow fix first and address the other components separately, or handle the mutation protection through a shared deserialization approach.
Thanks as well for avoiding conflicting work while #13421 is under review.
Hi! I've been investigating the remaining deserialization mutation cases, particularly in the compaction components.
I noticed the related fixes in #13421 and #13471. Would it be useful if I picked up the remaining compaction cases as a separate contribution once #13421 is merged?
I'd be happy to investigate and prepare a focused fix with regression tests, while avoiding overlap with the existing work.
Thanks for checking the remaining cases and for avoiding overlap with #13421. A separate focused contribution for the compaction components sounds reasonable to me, but I’ll leave the preferred scope and sequencing to the maintainers.
Hi, I have a focused bug-fix PR open for MetadataRouter deserialization input mutation: #13421. The regression and fix have been independently verified. Could someone advise whether the maintainers prefer the narrow component fix or a shared deserialization approach?
Activity
Hs1000 commentedon Oct 24, 2026
I reproduced this on macOS / Python 3.11 at 76fc2d3. It doesn't seem specific to MetadataRouter: I ran to_dict() → from_dict(d) → from_dict(d) across components, and the input dict was mutated (and the second call failed) for ListJoiner, InMemoryBM25Retriever, InMemoryEmbeddingRetriever, DocumentWriter, ChatPromptBuilder, MockChatGenerator, DocumentSplitter, DocumentPreprocessor, PyPDFToDocument, PDFMinerToDocument, DOCXToDocument, OpenAIChatGenerator, Agent, FaithfulnessEvaluator, LLMEvaluator, Tool and SuperComponent. Only BranchJoiner (fixed in #12935) leaves its input unchanged. Pipeline.from_dict() is not affected, so this hits direct component-level from_dict() calls and nested deserialization.
Would maintainers prefer per-component fixes like #12935, or a shared approach (e.g. shallow-copying init_parameters before the *_inplace helpers)? Happy to help with follow-up PRs once #13421 lands, so as not to conflict with it.
Quantum-Enigma-dot commentedon Oct 24, 2026
Thanks for testing this across the wider component set. That confirms the caller-mutation pattern extends beyond the MetadataRouter-specific case reported here.
I kept #13421 intentionally scoped to MetadataRouter so the regression test and behavior change remain focused. I’ll wait for maintainer guidance on whether the preferred direction is to merge this narrow fix first and address the other components separately, or handle the mutation protection through a shared deserialization approach.
Thanks as well for avoiding conflicting work while #13421 is under review.
Jenil1905 commentedon Oct 31, 2026
Hi! I've been investigating the remaining deserialization mutation cases, particularly in the compaction components.
I noticed the related fixes in #13421 and #13471. Would it be useful if I picked up the remaining compaction cases as a separate contribution once #13421 is merged?
I'd be happy to investigate and prepare a focused fix with regression tests, while avoiding overlap with the existing work.
Thanks!
Quantum-Enigma-dot commentedon Oct 31, 2026
Thanks for checking the remaining cases and for avoiding overlap with #13421. A separate focused contribution for the compaction components sounds reasonable to me, but I’ll leave the preferred scope and sequencing to the maintainers.
Quantum-Enigma-dot commentedon Nov 1, 2026
Hi, I have a focused bug-fix PR open for MetadataRouter deserialization input mutation: #13421. The regression and fix have been independently verified. Could someone advise whether the maintainers prefer the narrow component fix or a shared deserialization approach?