diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1169a0a3..15ab6545 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,12 +11,12 @@ repos: - id: isort args: [ "--profile", "black", "--filter-files" ] - repo: https://github.com/psf/black - rev: 23.9.1 + rev: 23.10.1 hooks: - id: black - language_version: python3.10 + language_version: python3.11 - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v1.6.0" + rev: v1.6.1 hooks: - id: mypy files: ^(cloudevents/) @@ -24,4 +24,4 @@ repos: types: [ python ] args: [ ] additional_dependencies: - - 'pydantic' + - "pydantic" diff --git a/CHANGELOG.md b/CHANGELOG.md index 44e991b5..51fcb0e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.10.1] + +### Fixed +- Fixed Pydantic v2 `to_json` (and `to_structured`) conversion ([#229]) + ## [1.10.0] — 2023-09-25 ### Added - Pydantic v2 support. ([#219]) @@ -185,6 +190,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Initial release +[1.10.1]: https://github.com/cloudevents/sdk-python/compare/1.10.0...1.10.1 [1.10.0]: https://github.com/cloudevents/sdk-python/compare/1.9.0...1.10.0 [1.9.0]: https://github.com/cloudevents/sdk-python/compare/1.8.0...1.9.0 [1.8.0]: https://github.com/cloudevents/sdk-python/compare/1.7.0...1.8.0 @@ -266,3 +272,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#218]: https://github.com/cloudevents/sdk-python/pull/218 [#219]: https://github.com/cloudevents/sdk-python/pull/219 [#221]: https://github.com/cloudevents/sdk-python/pull/221 +[#229]: https://github.com/cloudevents/sdk-python/pull/229 diff --git a/cloudevents/__init__.py b/cloudevents/__init__.py index 1cabc336..c6e11514 100644 --- a/cloudevents/__init__.py +++ b/cloudevents/__init__.py @@ -12,4 +12,4 @@ # License for the specific language governing permissions and limitations # under the License. -__version__ = "1.10.0" +__version__ = "1.10.1" diff --git a/cloudevents/pydantic/v1/event.py b/cloudevents/pydantic/v1/event.py index cd387014..d18736a4 100644 --- a/cloudevents/pydantic/v1/event.py +++ b/cloudevents/pydantic/v1/event.py @@ -186,7 +186,7 @@ def __init__( # type: ignore[no-untyped-def] ) attributes = {k.lower(): v for k, v in attributes.items()} kwargs.update(attributes) - super(CloudEvent, self).__init__(data=data, **kwargs) + super().__init__(data=data, **kwargs) class Config: extra: str = "allow" # this is the way we implement extensions diff --git a/cloudevents/pydantic/v2/event.py b/cloudevents/pydantic/v2/event.py index 17ed8d97..4ae8bb5c 100644 --- a/cloudevents/pydantic/v2/event.py +++ b/cloudevents/pydantic/v2/event.py @@ -134,7 +134,7 @@ def __init__( # type: ignore[no-untyped-def] ) attributes = {k.lower(): v for k, v in attributes.items()} kwargs.update(attributes) - super(CloudEvent, self).__init__(data=data, **kwargs) + super().__init__(data=data, **kwargs) model_config = ConfigDict( extra="allow", # this is the way we implement extensions @@ -209,7 +209,7 @@ def _ce_json_dumps(self) -> typing.Dict[str, typing.Any]: def _get_attributes(self) -> typing.Dict[str, typing.Any]: return { key: conversion.best_effort_encode_attribute_value(value) - for key, value in self.__dict__.items() + for key, value in dict(BaseModel.__iter__(self)).items() if key not in ["data"] } diff --git a/cloudevents/tests/test_pydantic_conversions.py b/cloudevents/tests/test_pydantic_conversions.py index 4beb981a..801b76bd 100644 --- a/cloudevents/tests/test_pydantic_conversions.py +++ b/cloudevents/tests/test_pydantic_conversions.py @@ -33,9 +33,9 @@ test_attributes = { "type": "com.example.string", "source": "https://example.com/event-producer", + "extension-attribute": "extension-attribute-test-value", } - _pydantic_implementation = { "v1": { "event": PydanticV1CloudEvent,