From ed6f61a910bd4511967b97ed70b588368530ef8b Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Fri, 10 Nov 2023 16:08:03 +0000 Subject: [PATCH 1/2] fix(client): serialise pydantic v1 default fields correctly in params (#247) --- src/lithic/_utils/_transform.py | 2 +- tests/test_transform.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/lithic/_utils/_transform.py b/src/lithic/_utils/_transform.py index dc497ea3..d953505f 100644 --- a/src/lithic/_utils/_transform.py +++ b/src/lithic/_utils/_transform.py @@ -168,7 +168,7 @@ def _transform_recursive( return data if isinstance(data, pydantic.BaseModel): - return model_dump(data, exclude_unset=True, exclude_defaults=True) + return model_dump(data, exclude_unset=True) return _transform_value(data, annotation) diff --git a/tests/test_transform.py b/tests/test_transform.py index f6e0666c..14c27b77 100644 --- a/tests/test_transform.py +++ b/tests/test_transform.py @@ -237,3 +237,29 @@ def test_pydantic_nested_objects() -> None: model = ModelNestedObjects.construct(nested={"foo": "stainless"}) assert isinstance(model.nested, MyModel) assert transform(model, Any) == {"nested": {"foo": "stainless"}} + + +class ModelWithDefaultField(BaseModel): + foo: str + with_none_default: Union[str, None] = None + with_str_default: str = "foo" + + +def test_pydantic_default_field() -> None: + # should be excluded when defaults are used + model = ModelWithDefaultField.construct() + assert model.with_none_default is None + assert model.with_str_default == "foo" + assert transform(model, Any) == {} + + # should be included when the default value is explicitly given + model = ModelWithDefaultField.construct(with_none_default=None, with_str_default="foo") + assert model.with_none_default is None + assert model.with_str_default == "foo" + assert transform(model, Any) == {"with_none_default": None, "with_str_default": "foo"} + + # should be included when a non-default value is explicitly given + model = ModelWithDefaultField.construct(with_none_default="bar", with_str_default="baz") + assert model.with_none_default == "bar" + assert model.with_str_default == "baz" + assert transform(model, Any) == {"with_none_default": "bar", "with_str_default": "baz"} From 0f54d9a73a701b321f48e51c71a31a21c6330223 Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Fri, 10 Nov 2023 16:08:23 +0000 Subject: [PATCH 2/2] release: 0.24.2 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 8 ++++++++ pyproject.toml | 2 +- src/lithic/_version.py | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index bed1c87d..69498b5e 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.24.1" + ".": "0.24.2" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index c5f3cb2f..606926d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.24.2 (2023-11-10) + +Full Changelog: [v0.24.1...v0.24.2](https://github.com/lithic-com/lithic-python/compare/v0.24.1...v0.24.2) + +### Bug Fixes + +* **client:** serialise pydantic v1 default fields correctly in params ([#247](https://github.com/lithic-com/lithic-python/issues/247)) ([ed6f61a](https://github.com/lithic-com/lithic-python/commit/ed6f61a910bd4511967b97ed70b588368530ef8b)) + ## 0.24.1 (2023-11-10) Full Changelog: [v0.24.0...v0.24.1](https://github.com/lithic-com/lithic-python/compare/v0.24.0...v0.24.1) diff --git a/pyproject.toml b/pyproject.toml index d601965b..891c413a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "lithic" -version = "0.24.1" +version = "0.24.2" description = "The official Python library for the lithic API" readme = "README.md" license = "Apache-2.0" diff --git a/src/lithic/_version.py b/src/lithic/_version.py index 851b86ac..0a449909 100644 --- a/src/lithic/_version.py +++ b/src/lithic/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. __title__ = "lithic" -__version__ = "0.24.1" # x-release-please-version +__version__ = "0.24.2" # x-release-please-version