-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
allow Config.field to update a Field #2461
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2461 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 25 25
Lines 5100 5109 +9
Branches 1048 1050 +2
=========================================
+ Hits 5100 5109 +9
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM otherwise! Just a question on constraints attributes that don't have None
as default value
pydantic/fields.py
Outdated
# attr_name is not an attribute of FieldInfo, it should therefore be added to extra | ||
self.extra[attr_name] = value | ||
else: | ||
if current_value is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if current_value is None: | |
if current_value is self.__field_constraints__.get(attr_name, None): |
I wonder if we should do this to support
from pydantic import BaseModel, Field
class Foo(BaseModel):
a: str = Field(...)
class Config:
validate_assignment = True
fields = {'a': {'allow_mutation': False}}
f = Foo(a='x')
f.a = 'y' # should fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL 😄 just saw your last commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha, I was just writing a comment about allow_mutation
.
63f83e7
to
9826145
Compare
For me this is now ready, I'll merge once passing. @PrettyWood are you okay for me to release v1.8.1 after this? I think we have fixed everything that has been reported. |
@samuelcolvin Yes! |
Change Summary
Allow element of
Config.field
to update elements of aField
Example of usage:
Related issue number
fix #2426
supersedes #2437
Questions
Checklist
changes/<pull request or issue id>-<github username>.md
file added describing change