MarshalX / atproto

The AT Protocol (🦋 Bluesky) SDK for Python 🐍

Home Page:https://atproto.blue

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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__ of DotDict to show it's a DotDict:

        def validate_from_dict(value: dict) -> DotDict:
            print("start", value)
            result = DotDict(value)
            print("result", result)
            print("end", value)
            return result

Then I see that calling DotDict(value) is replacing nested dictionaries inside value with DotDict 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 the DotDict validation was never run, on 2.5 it is now being run which is why you see the mutation bug arising.

ref: pydantic/pydantic#8349 (comment)