Skip to content

Hypothesis plugin not working with alias and special characters #5062

@galbino

Description

@galbino

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:
    pass

Python, 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug V1Bug related to Pydantic V1.Xtopic-hypothesisRelated to the Hypothesis testing library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions