Skip to content
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

Pattern validators not properly escaped #301

Open
jnicoulaud-ledger opened this issue Sep 10, 2024 · 2 comments
Open

Pattern validators not properly escaped #301

jnicoulaud-ledger opened this issue Sep 10, 2024 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@jnicoulaud-ledger
Copy link

When using this kind of types in models:

MyType = Annotated[str, Field(min_length=3, max_length=256, pattern=r"^[a-z0-9_]+$")]

It looks like the generator does not properly escape the regex as needed:

docstring of MyModel.some_field:1:Unknown target name: "a-z0-9".
@mansenfranzen
Copy link
Owner

Hi @jnicoulaud-ledger,

thanks for raising the issue here!

This looks like an awkward behavior. Could you please provide a minimal reproducible example including the code of the complete pydantic model, the pydantic version you're using and all non-default configurations (conf.py and directive options)? This will help reproduce the bug.

@mansenfranzen mansenfranzen added bug Something isn't working help wanted Extra attention is needed labels Sep 23, 2024
@gabicca
Copy link

gabicca commented Oct 28, 2024

Hi, I have the same problem. Here is an example and versions of code I'm using:

from pydantic import BaseModel, Field
from pydantic.config import ConfigDict

class Example(BaseModel):
    """
    Pointing offset script parameters
    """

    model_config = ConfigDict(title="example")

    version: Annotated[
        str,
        Field(
            pattern=r"^[a-zA-Z0-9_\.-]+$",
            default="0.1.1",
            title="My example failing class",
            description="autodoc_pydantic does not deal with regex correctly",
        ),
    ]

autodoc_pydantic==2.2.0
pydantic==2.9.2
python== 3.11.5

call in .rst .. autopydantic_settings:: mymodule.Example

In conf.py I just added the extension "sphinxcontrib.autodoc_pydantic", did not change anything else in the configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants