diff --git a/HISTORY.md b/HISTORY.md index 68a3e409030..698aac0e223 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,13 @@ +## v2.8.2 (2024-07-03) + +[GitHub release](https://github.com/pydantic/pydantic/releases/tag/v2.8.2) + +### What's Changed + +#### Fixes + +* Fix issue with assertion caused by pluggable schema validator by @dmontagu in [#9838](https://github.com/pydantic/pydantic/pull/9838) + ## v2.8.1 (2024-07-03) [GitHub release](https://github.com/pydantic/pydantic/releases/tag/v2.8.1) @@ -5,13 +15,15 @@ ### What's Changed #### Packaging -* Bump `ruff` to `v0.5.0` and `pyright` to `v1.1.369` by @sydney-runkle in https://github.com/pydantic/pydantic/pull/9801 -* Bump `pydantic-core` to `v2.20.1`, `pydantic-extra-types` to `v2.9.0` by @sydney-runkle in https://github.com/pydantic/pydantic/pull/9832 +* Bump `ruff` to `v0.5.0` and `pyright` to `v1.1.369` by @sydney-runkle in [#9801](https://github.com/pydantic/pydantic/pull/9801) +* Bump `pydantic-core` to `v2.20.1`, `pydantic-extra-types` to `v2.9.0` by @sydney-runkle in [#9832](https://github.com/pydantic/pydantic/pull/9832) #### Fixes -* Fix breaking change in `to_snake` from v2.7 -> v2.8 by @sydney-runkle in https://github.com/pydantic/pydantic/pull/9812 -* Fix list constraint json schema application by @sydney-runkle in https://github.com/pydantic/pydantic/pull/9818 -* Fix issue with assertion caused by pluggable schema validator by @dmontagu in https://github.com/pydantic/pydantic/pull/9838 +* Fix breaking change in `to_snake` from v2.7 -> v2.8 by @sydney-runkle in [#9812](https://github.com/pydantic/pydantic/pull/9812) +* Fix list constraint json schema application by @sydney-runkle in [#9818](https://github.com/pydantic/pydantic/pull/9818) +* Support time duration more than 23 by @nix010 in [pydantic/speedate#64](https://github.com/pydantic/speedate/pull/64) +* Fix millisecond fraction being handled with the wrong scale by @davidhewitt in [pydantic/speedate#65](https://github.com/pydantic/speedate/pull/65) +* Handle negative fractional durations correctly by @sydney-runkle in [pydantic/speedate#71](https://github.com/pydantic/speedate/pull/71) ## v2.8.0 (2024-07-01) diff --git a/pydantic/_internal/_dataclasses.py b/pydantic/_internal/_dataclasses.py index 1fbbfc694e8..73272922ad4 100644 --- a/pydantic/_internal/_dataclasses.py +++ b/pydantic/_internal/_dataclasses.py @@ -18,7 +18,7 @@ from ..errors import PydanticUndefinedAnnotation from ..fields import FieldInfo -from ..plugin._schema_validator import create_schema_validator +from ..plugin._schema_validator import PluggableSchemaValidator, create_schema_validator from ..warnings import PydanticDeprecatedSince20 from . import _config, _decorators, _typing_extra from ._fields import collect_dataclass_fields @@ -58,7 +58,7 @@ class PydanticDataclass(StandardDataclass, typing.Protocol): __pydantic_decorators__: ClassVar[_decorators.DecoratorInfos] __pydantic_fields__: ClassVar[dict[str, FieldInfo]] __pydantic_serializer__: ClassVar[SchemaSerializer] - __pydantic_validator__: ClassVar[SchemaValidator] + __pydantic_validator__: ClassVar[SchemaValidator | PluggableSchemaValidator] else: # See PyCharm issues https://youtrack.jetbrains.com/issue/PY-21915 diff --git a/pydantic/_internal/_mock_val_ser.py b/pydantic/_internal/_mock_val_ser.py index 063918a60c4..3e55af70dc7 100644 --- a/pydantic/_internal/_mock_val_ser.py +++ b/pydantic/_internal/_mock_val_ser.py @@ -1,18 +1,19 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Callable, Generic, Iterator, Mapping, TypeVar +from typing import TYPE_CHECKING, Any, Callable, Generic, Iterator, Mapping, TypeVar, Union from pydantic_core import CoreSchema, SchemaSerializer, SchemaValidator from typing_extensions import Literal from ..errors import PydanticErrorCodes, PydanticUserError +from ..plugin._schema_validator import PluggableSchemaValidator if TYPE_CHECKING: from ..dataclasses import PydanticDataclass from ..main import BaseModel -ValSer = TypeVar('ValSer', SchemaValidator, SchemaSerializer) +ValSer = TypeVar('ValSer', bound=Union[SchemaValidator, PluggableSchemaValidator, SchemaSerializer]) T = TypeVar('T') diff --git a/pydantic/main.py b/pydantic/main.py index e09569a00cf..c40c818b498 100644 --- a/pydantic/main.py +++ b/pydantic/main.py @@ -47,6 +47,7 @@ from .config import ConfigDict from .errors import PydanticUndefinedAnnotation, PydanticUserError from .json_schema import DEFAULT_REF_TEMPLATE, GenerateJsonSchema, JsonSchemaMode, JsonSchemaValue, model_json_schema +from .plugin._schema_validator import PluggableSchemaValidator from .warnings import PydanticDeprecatedSince20 # Always define certain types that are needed to resolve method type hints/annotations @@ -142,7 +143,7 @@ class BaseModel(metaclass=_model_construction.ModelMetaclass): __pydantic_post_init__: ClassVar[None | Literal['model_post_init']] __pydantic_root_model__: ClassVar[bool] __pydantic_serializer__: ClassVar[SchemaSerializer] - __pydantic_validator__: ClassVar[SchemaValidator] + __pydantic_validator__: ClassVar[SchemaValidator | PluggableSchemaValidator] # Instance attributes __pydantic_extra__: dict[str, Any] | None = _PrivateAttr() diff --git a/pydantic/plugin/_schema_validator.py b/pydantic/plugin/_schema_validator.py index f4772b63c2d..21287f4456a 100644 --- a/pydantic/plugin/_schema_validator.py +++ b/pydantic/plugin/_schema_validator.py @@ -26,7 +26,7 @@ def create_schema_validator( schema_kind: SchemaKind, config: CoreConfig | None = None, plugin_settings: dict[str, Any] | None = None, -) -> SchemaValidator: +) -> SchemaValidator | PluggableSchemaValidator: """Create a `SchemaValidator` or `PluggableSchemaValidator` if plugins are installed. Returns: @@ -45,7 +45,7 @@ def create_schema_validator( config, plugins, plugin_settings or {}, - ) # type: ignore + ) else: return SchemaValidator(schema, config) diff --git a/pydantic/type_adapter.py b/pydantic/type_adapter.py index 5d15ede3a3e..d6001df0fdb 100644 --- a/pydantic/type_adapter.py +++ b/pydantic/type_adapter.py @@ -38,7 +38,7 @@ JsonSchemaMode, JsonSchemaValue, ) -from .plugin._schema_validator import create_schema_validator +from .plugin._schema_validator import PluggableSchemaValidator, create_schema_validator T = TypeVar('T') R = TypeVar('R') @@ -253,7 +253,7 @@ def __init__( self._module_name = module self._core_schema: CoreSchema | None = None - self._validator: SchemaValidator | None = None + self._validator: SchemaValidator | PluggableSchemaValidator | None = None self._serializer: SchemaSerializer | None = None if not self._defer_build(): @@ -311,11 +311,11 @@ def core_schema(self) -> CoreSchema: @cached_property @_frame_depth(2) # +2 for @cached_property + validator(self) - def validator(self) -> SchemaValidator: + def validator(self) -> SchemaValidator | PluggableSchemaValidator: """The pydantic-core SchemaValidator used to validate instances of the model.""" - if not isinstance(self._validator, SchemaValidator): + if not isinstance(self._validator, (SchemaValidator, PluggableSchemaValidator)): self._init_core_attrs(rebuild_mocks=True) # Do not expose MockValSer from public function - assert isinstance(self._validator, SchemaValidator) + assert isinstance(self._validator, (SchemaValidator, PluggableSchemaValidator)) return self._validator @cached_property diff --git a/pydantic/version.py b/pydantic/version.py index 8f30cb61bd5..fa69a3a8f59 100644 --- a/pydantic/version.py +++ b/pydantic/version.py @@ -4,7 +4,7 @@ __all__ = 'VERSION', 'version_info' -VERSION = '2.8.1' +VERSION = '2.8.2' """The version of Pydantic.""" diff --git a/tests/test_plugins.py b/tests/test_plugins.py index f1a15119b55..8616a533c76 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -341,7 +341,8 @@ def new_schema_validator(self, schema, schema_type, schema_type_path, schema_kin plugin = Plugin() with install_plugin(plugin): - TypeAdapter(List[str]) + adapter = TypeAdapter(List[str]) + adapter.validate_python(['a', 'b']) def test_plugin_path_type_adapter_with_module() -> None: