-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed as not planned
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.Xtopic-hypothesisRelated to the Hypothesis testing libraryRelated to the Hypothesis testing library
Description
Initial Checks
- I have searched GitHub for a duplicate issue and I'm sure this is something new
- I have searched Google & StackOverflow for a solution and couldn't find anything
- I have read and followed the docs and still think this is a bug
- I am confident that the issue is with pydantic (not my code, or another library in the ecosystem like FastAPI or mypy)
Description
Hi, I have a schema that uses an alias containing $ within its name and it seems that, on that case, hypothesis can't generate input values for it and it raises the following error:
> ???
E pydantic.error_wrappers.ValidationError: 1 validation error for ExampleSchemaBad
E $example
E field required (type=value_error.missing)
pydantic/main.py:342: ValidationError
FAILED tests/unit/test_pylint.py::test_dollar_sign - pydantic.error_wrappers.ValidationError: 1 validation error for ExampleSchemaBad
Apparently the issue isn't only with the dollar sign, but with all special characters
Example Code
import hypothesis
import pydantic
from hypothesis import strategies as st
class ExampleSchemaBad(pydantic.BaseModel):
example: str = pydantic.Field(alias="$example")
class ExampleSchemaGood(pydantic.BaseModel):
example: str = pydantic.Field(alias="other")
@hypothesis.given(
request=st.builds(
ExampleSchemaBad,
)
)
def test_dollar_sign(
request: ExampleSchemaBad,
) -> None:
pass
@hypothesis.given(request=st.builds(ExampleSchemaGood))
def test_clean(
request: ExampleSchemaGood,
) -> None:
passPython, Pydantic & OS Version
pydantic version: 1.10.4
pydantic compiled: True
python version: 3.10.5 (main, Oct 3 2022, 09:43:47) [Clang 13.1.6 (clang-1316.0.21.2.5)]
platform: macOS-13.2-arm64-arm-64bit
optional deps. installed: ['typing-extensions']
Affected Components
- Compatibility between releases
- Data validation/parsing
- Data serialization -
.model_dump()and.model_dump_json() - JSON Schema
- Dataclasses
- Model Config
- Field Types - adding or changing a particular data type
- Function validation decorator
- Generic Models
- Other Model behaviour -
model_construct(), pickling, private attributes, ORM mode - Plugins and integration with other tools - mypy, FastAPI, python-devtools, Hypothesis, VS Code, PyCharm, etc.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.Xtopic-hypothesisRelated to the Hypothesis testing libraryRelated to the Hypothesis testing library