We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Please complete:
I am sorta lost as to why this isn't working as expected for me in v1.2:
from typing import Type, TypeVar import pydantic class ConnectionName(pydantic.StrictStr): min_length = 1 class EndpointStr(pydantic.StrictStr): min_length = 1 DEFAULT_ENDPOINT = EndpointStr("default") T = TypeVar("T", bound="UpRequestEvent") class UpRequestEvent(pydantic.BaseModel): connection_name: ConnectionName # connection name connection_endpoint: EndpointStr # connection name's endpoint (for server type connections) @classmethod def build_from( cls: Type[T], connection_name: ConnectionName, connection_endpoint: EndpointStr = DEFAULT_ENDPOINT, **kwargs ) -> T: return cls( connection_name=connection_name, connection_endpoint=connection_endpoint, ) class Config: use_enum_values = True # This works UpRequestEvent.build_from( connection_name="test", connection_endpoint="default", ) # This fails UpRequestEvent.build_from( connection_name=ConnectionName("test"), connection_endpoint=EndpointStr("default"), )
Traceback (most recent call last): File "/opt/pycharm-eap/plugins/python/helpers/pydev/pydevd.py", line 1415, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "/opt/pycharm-eap/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "/home/spalmer1009/.PyCharm2019.3/config/scratches/scratch.py", line 44, in <module> connection_name=ConnectionName("test"), connection_endpoint=EndpointStr("default"), File "/home/spalmer1009/.PyCharm2019.3/config/scratches/scratch.py", line 30, in build_from connection_endpoint=connection_endpoint, File "pydantic/main.py", line 274, in pydantic.main.BaseModel.__init__ pydantic.error_wrappers.ValidationError: 2 validation errors for UpRequestEvent connection_name Expected unicode, got ConnectionName (type=type_error) connection_endpoint Expected unicode, got EndpointStr (type=type_error)
My special types ConnectionName and EndpointStr are a subclass of str (through StrictStr -> ConstrainedStr)
str
StrictStr
ConstrainedStr
As discovered by @dmontagu the issue only seems to exist when the code is Cython compiled.
The text was updated successfully, but these errors were encountered:
pydantic.constr()
uprev speedate, prevent - sign as datetime (pydantic#1060)
1cf1c75
Successfully merging a pull request may close this issue.
Bug
Please complete:
Original bug discussion in #799
I am sorta lost as to why this isn't working as expected for me in v1.2:
My special types ConnectionName and EndpointStr are a subclass of
str
(throughStrictStr
->ConstrainedStr
)As discovered by @dmontagu the issue only seems to exist when the code is Cython compiled.
The text was updated successfully, but these errors were encountered: