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
Question: required Optional[Object] possible? #263
Comments
I think it's related to #132 but not quite the same. The origin of this behaviour was my frustration with trafaret, where I constantly forgot to mark fields as both nullable and not required. If you ask me should "nullable" imply "not required". I agree that theoretically this is not always going to be what people require, but practically for purposes, it's fine. The "zen" (perhaps a bad word to use around python atm. 😉) of pydantic (and perhaps this should be documented somewhere) is "the resulting modal will always take this form", not "the input data was correctly formed". In other words it is primarily a data parsing library not a data validation library. All that said, I'd happily accept a PR to clarify that |
no reply... |
I've just come across this now. Now
(forget about what Point is, if one leaves 'data' out of the model then it has a very semantic different meaning to explicitly telling it that the Whether we're parsing or validating, we never explicitly told the model to use None as the default. |
ye, I can see your problem, however I think it would require a significant change to pydantic to change this behaviour. I'm prepared to consider changing the behaviour for Feel free to have a go at it, but I warn you:
|
After I went and read through the related issues and the topic of parsing vs validation for pydantic I kinda get it now. My use case is a validation use case which is different. Issues like mine are very simply solved by moving the problem to a validation space. |
Doesn't make sense for something with the word "optional" to be required, closing this. |
* helper functions for creating schemas * fix core_schema types * fix conftest types
import sys; print(sys.version)
: 3.6.6import pydantic; print(pydantic.VERSION)
: 0.13Based on my interpretation of the following documentation
the annotation only declaration tells pydantic that this field is required
and
The ellipsis ... just means “Required” same as annotation only declarations above.
and with this model
I would not expect the following result.
In the above example I can create a model without actually specifying the
required
attributesstr_or_none
andstr_or_none_with_ellipse
. Without me specifying any value, a default value ofNone
is assigned to these attributes, contrary to what the documentation says.The documentation have many places where
None
is set explicitly as the default value even if it's not needed by the current behaviour.Is it intentional that
Optional[]
assignsNone
to the attribute even without me specifying a default value? And if so, what is the reasoning for this undocumented behaviour?The text was updated successfully, but these errors were encountered: