-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
More support for deprecated fields/models #8922
Comments
Agreed. PRs welcome for parts or all of the above features. Ping me if you want to chat more about implementation details :). |
@sydney-runkle @Viicos I had started to look into implementing point 4, and from my testing, the My question is, should a warning also be emitted in the following scenario? @deprecated
class DeprecatedModel(BaseModel):
pass
class NewModel(BaseModel):
field: DeprecatedModel Do you think that in this case Pydantic should emit a warning along the lines of |
That's great to hear!
Do you mean the warning should be emitted during class creation? (And thus whenever the model's module is imported). |
I actually meant to emit a warning when a user defines a model with one of its fields being a deprecated model, not when the deprecated model is created/imported. In my examples above, when creating |
Also, just a side note, I don't think we should support the config based deprecation above, but the deprecated decorator approach is great. |
Initial Checks
Description
#8237 implemented support for deprecated fields. While doing so, we encountered/postponed some extra features that could be nice to have:
When using the
deprecated
decorator class, extra information (such as thecategory
andstacklevel
) can be passed. It would be great if Pydantic could support such attributes when emitting the runtime warning. For reference, this commit implements the feature: cf06a73 (extra care should be taken with thetyping-extensions
version -- Only 4.9.0 and greater support the class implementation of thedeprecated
decorator).When instantiating a model with a deprecated field explicitly specified (
Model(deprecated_field=...)
), the runtime warning could be emitted.Support for Pydantic/stdlib dataclasses: not sure if there are any technical limitations for this one?
Support for deprecated models:
@deprecated
decorator:Field
:computed_field
)These were the ideas I had while implementing support for deprecated fields. Some of them requires some discussion, as I'm not sure whether it should be supported or not. Happy to hear your opinions
Affected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: