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
Required optional field has a default value of None after v1.7.0 #2142
Comments
Alright, I haven't looked really closely, but here's my guess: UPD1: And here's where "bar" is created and gets the default value of UPD2: Is it a good idea to check |
Hello @leovp and thanks for reporting :) |
@PrettyWood |
* fix: ignore `__doc__` as valid private attribute (#2091) closes #2090 * Fixes a regression where Enum fields would not propagate keyword arguments to the schema (#2109) fix #2108 * Fix schema extra not being included when field type is Enum * Code format * More code format * Add changes file Co-authored-by: Ben Martineau <b.martineau@iwoca.co.uk> * fix: update all modified field values in `root_validator` when `validate_assignment` is on (#2119) * fix: update all modified field values in `root_validator` when `validate_assignment` is on closes #2116 * chore: update root_validator name Co-authored-by: Arthur Pastel <arthur.pastel@gmail.com> Co-authored-by: Arthur Pastel <arthur.pastel@gmail.com> * fix: support `underscore_attrs_are_private` with generic models (#2139) closes #2138 * fix: set right default value for required (optional) fields (#2143) closes #2142 * Fix #2111: support pickle for built-in dataclasses (#2114) * 2111: support pickle for built-in dataclasses * 2111: add changes * 2111: simplify test * return original name + handle similar names * add additional check * fix a misspell * remove useless f-string * cleanup test Co-authored-by: Samuel Colvin <s@muelcolvin.com> * uprev and add history * tempoarily pin pip Co-authored-by: Eric Jolibois <em.jolibois@gmail.com> Co-authored-by: Ben Martineau <bm424@cam.ac.uk> Co-authored-by: Ben Martineau <b.martineau@iwoca.co.uk> Co-authored-by: Arthur Pastel <arthur.pastel@gmail.com> Co-authored-by: aimestereo <aimestereo@gmail.com>
Checks
Bug
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:It seems that
pydantic
thinksbar
(a "required optional" field) has a default value of None and serializes the model without this key, which makes it non-deserializable. This was not the case on versions 1.5.x and 1.6.x, so I think it's a regression. (Or maybe it was never a guarantee).According to
git bisect
the potential regression was introduced in commit 4bc4230.The text was updated successfully, but these errors were encountered: