aio-libs / aio-libs/yarl

docs: arbitrary_types_allowed needed in Pydantic example

Ouverte
#1,624 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
bug documentation
Langage dominant
Python
Étoiles
1.5k
Forks
215
Merge moyen
1 j 2 min
PR mergées (30 j)
13

Description

### Please confirm the following

- [x] I agree to follow the [aio-libs Code of Conduct][CoC]

[CoC]: ../../.github/blob/master/CODE_OF_CONDUCT.md

- [x] I have checked the [current issues][issue search] for duplicates.

[issue search]: ../search?q=is%3Aissue&type=issues

- [x] I understand this is open source software provided for free and that I might not receive a timely response.
- [x] I am positive I am **NOT** reporting a (potential) security
vulnerability, to the best of my knowledge. *(These must be shared by
submitting [this report form][vulnerability report form] instead, if
any hesitation exists.)*

[vulnerability report form]: ../security/advisories/new

- [ ] I am willing to submit a pull request with reporoducers as xfailing test cases or even entire fix. *(Assign this issue to me.)*

### Describe the bug

In https://yarl.aio-libs.org/en/latest/#why-isn-t-boolean-supported-by-the-url-query-api it is stated that:

> The [URL](https://yarl.aio-libs.org/en/latest/api/#yarl.URL) could be used as a field type in [pydantic](https://docs.pydantic.dev/latest/) models seamlessly:
>
> ```py
> from pydantic import BaseModel
> from yarl import URL
>
> class Model(BaseModel):
> url: URL
> ```

However, the example does not work out of the box:

```
PydanticSchemaGenerationError: Unable to generate pydantic-core schema for . Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.

If you got this error by calling handler() within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema()` since we do not call `__get_pydantic_core_schema__` on `` otherwise to avoid infinite recursion.

For further information visit https://errors.pydantic.dev/2.12/u/schema-for-unknown-type
```

The working example would be:

```py
In [20]: class C(pydantic.BaseModel):
...: model_config = pydantic.ConfigDict(arbitrary_types_allowed=True)
...: endpoint: yarl.URL
```

Versions tested:
```
In [23]: pydantic.__version__
Out[23]: '2.12.5'

In [24]: yarl.__version__
Out[24]: '1.22.0'

In [26]: sys.version
Out[26]: '3.10.11 (v3.10.11:7d4cc5aa85, Apr 4 2023, 19:05:19) [Clang 13.0.0 (clang-1300.0.29.30)]'
```

### To Reproduce

...

### Expected behavior

...

### Logs/tracebacks

```python-traceback
...
```

### Python Version

```console
In [26]: sys.version
Out[26]: '3.10.11 (v3.10.11:7d4cc5aa85, Apr 4 2023, 19:05:19) [Clang 13.0.0 (clang-1300.0.29.30)]'
```

### multidict Version

```console
In [28]: multidict.__version__
Out[28]: '6.7.1'
```

### propcache Version

```console
In [31]: propcache.__version__
Out[31]: '0.4.1'
```

### yarl Version

```console
In [24]: yarl.__version__
Out[24]: '1.22.0'
```

### OS

macOS

### Additional context

Pls consider simplifying the bug report form 🙏🏻

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.