-
Notifications
You must be signed in to change notification settings - Fork 246
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
Raise warnings when deprecated fields are filled at model instantiation #1551
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1551 +/- ##
==========================================
- Coverage 90.21% 89.61% -0.61%
==========================================
Files 106 112 +6
Lines 16339 17895 +1556
Branches 36 40 +4
==========================================
+ Hits 14740 16036 +1296
- Misses 1592 1839 +247
- Partials 7 20 +13
... and 54 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
CodSpeed Performance ReportMerging #1551 will not alter performanceComparing Summary
|
Please review. Meanwhile, I'd like to ask the reviewer's opinion on how we can make this thing "less slow". Since this implementation calls Since we know that performance will definitely be impacted, we can try to mitigate this. For instance, instead of calling import each time a deprecated field is filled, we can collect warnings and raise them all together in one warning at the end. There are some issues with this approach though. First, the final warning message will need to be more specific because all deprecation messages will be mixed up. We will need to indicate which fields are deprecated and which message belongs to which field for clarity, but this will be inconsistent with what is implemented in pydantic now, i.e. print the deprecation warning only without any additional information. Maybe we can just implement that here and change pydantic later on. Another issue is when that final warning should be raised. Currently |
Change Summary
Raise warnings when deprecated fields receive values at model instantiation. My previous attempt at pydantic/pydantic#10865 was rejected because it led to performance issues, so I'm hoping that by moving the logic to pydantic-core will work better. At least doing it here means that the code won't need to loop over the input values one more time.
One extra config is added to the
model-field
schema:deprecation_msg
(Option<String>
). A field is marked as deprecated when this config value is present. The actual deprecation message will be passed in from pydantic; this keeps handling the type of the deprecation message simple, and most importantly, there is already logic over there dealing with possible cases of deprecation messages and thus we should not duplicate the logic here.Also tested with pydantic and it worked.
Related issue number
Part of pydantic/pydantic#8922
Checklist
pydantic-core
(except for expected changes)Selected Reviewer: @sydney-runkle