DotDict mutates input data
MarshalX opened this issue · comments
Thanks for sharing. The mutation is happening in your
DotDict
validator. If I add some prints, and adjust your__repr__
ofDotDict
to show it's aDotDict
:def validate_from_dict(value: dict) -> DotDict: print("start", value) result = DotDict(value) print("result", result) print("end", value) return resultThen I see that calling
DotDict(value)
is replacing nested dictionaries insidevalue
withDotDict
instances.The reason why this has only broken with the bump to 2.5 is that on 2.5 the new union behaviour is doing a little bit more work than before to check that
DotDict
is not a better match than your model instances. On 2.4 theDotDict
validation was never run, on 2.5 it is now being run which is why you see the mutation bug arising.