Replies: 2 comments 4 replies
-
|
Beta Was this translation helpful? Give feedback.
-
It seems to be fixed, at least in version Why does the id of the mutable default value change? However, it is not the case! The default value is deep copied using the pydantic._internals._utils.smart_deepcopy method. It is called in FieldInfo.get_default, which is the parent of fastapi.params.Param. I have just started to review the code and docs of these amazing projects and might be wrong. However, I had the same question and I am guessing this is a convincing one. |
Beta Was this translation helpful? Give feedback.
-
Hi All!
I've searched the docs, but I'm hoping someone may be able to confirm the behavior for me. Once confirmed, I am happy to provide a PR with a small clarification in the (amazing) docs.
In many frameworks (e.g.
dataclasses
), there is adefault_factory
argument for fields, which is used for mutable types. This doesn't appear to be available in FastAPI. Are there any issues with mutable defaults in FastAPI?For example, we may have a body like this:
In this case, are there any issues or risks related to the default being mutable, or is this a non-issue in the FastAPI implementation?
Thank you in advance for any help you can give!
Beta Was this translation helpful? Give feedback.
All reactions