-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dict(model)
errors when field name keys
exists
#10575
Comments
dict(model)
errors when keys
field name existsdict(model)
errors when field name keys
exists
Hello @zzstoatzz, you are hitting an annoying Python behavior reported here. I'm going to try to update the Python documentation because the behavior is probably going to stay the same. As a workaround (which I'm going to document in the Pydantic documentation), you can call |
Closing for now, I think this issue represents good enough documentation of this problem + workaround. Thanks @Viicos! |
thanks for the info @Viicos - sounds good! 👍 |
Docs PR, hopefully this will be clarified: python/cpython#125213 |
Initial Checks
Description
A user of ours opened this issue, which appeared to show that dumping a model with
dict(...)
breaks if you have field on the model whose name is literallykeys
- which I was able to reproduce.This error was certainly unexpected to me - I couldn't find an open or closed related issue, but apologies if I'm missing something. I couldn't immediately find a fix for this looking at
BaseModel.__iter__
and a bit elsewhere, but will come back to this to try and add a fix later.Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: