From d81cdb187c1de43507bb458daacf9e306d42f487 Mon Sep 17 00:00:00 2001 From: dblock Date: Fri, 17 Nov 2023 15:55:22 -0500 Subject: [PATCH 1/2] Fix invalid value type. Signed-off-by: dblock --- opensearchpy/helpers/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensearchpy/helpers/utils.py b/opensearchpy/helpers/utils.py index 2a9f19da..a27ec9a4 100644 --- a/opensearchpy/helpers/utils.py +++ b/opensearchpy/helpers/utils.py @@ -309,7 +309,7 @@ def __eq__(self, other: Any) -> bool: def __ne__(self, other: Any) -> bool: return not self == other - def __setattr__(self, name: str, value: Optional[bool]) -> None: + def __setattr__(self, name: str, value: Any) -> None: if name.startswith("_"): return super(DslBase, self).__setattr__(name, value) return self._setattr(name, value) From ffa5944bce20e03e637e56302a377decd6442283 Mon Sep 17 00:00:00 2001 From: dblock Date: Fri, 17 Nov 2023 16:00:03 -0500 Subject: [PATCH 2/2] Workaround Incompatible types in assignment (expression has type float, variable has type Double) [assignment] Signed-off-by: dblock --- CHANGELOG.md | 1 + .../test_helpers/test_document.py | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69bdda60..26f07df4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Fixed - Fix `TypeError` on `parallel_bulk` ([#601](https://github.com/opensearch-project/opensearch-py/pull/601)) - Fix Amazon OpenSearch Serverless integration with LangChain ([#603](https://github.com/opensearch-project/opensearch-py/pull/603)) +- Fix type of `Field.__setattr__` ([604](https://github.com/opensearch-project/opensearch-py/pull/604)) ### Security ## [2.4.1] diff --git a/test_opensearchpy/test_helpers/test_document.py b/test_opensearchpy/test_helpers/test_document.py index e1b5e5c4..1a156ad8 100644 --- a/test_opensearchpy/test_helpers/test_document.py +++ b/test_opensearchpy/test_helpers/test_document.py @@ -32,7 +32,7 @@ import pickle from datetime import datetime from hashlib import sha256 -from typing import Any +from typing import Any, Union from pytest import raises @@ -648,3 +648,28 @@ class MySubDocWithNested(MyDoc): }, "title": {"type": "keyword"}, } + + +def test_save_double(mock_client: Any) -> None: + class MyDocumentWithDouble(MyDoc): + a_double: Union[float, field.Double] = field.Double() + + def save( + self, + using: Any = None, + index: Any = None, + validate: bool = True, + skip_empty: bool = True, + return_doc_meta: bool = False, + **kwargs: Any, + ) -> Any: + if not self.a_double: + self.a_double = 3.14159265359 + return super().save( + using, index, validate, skip_empty, return_doc_meta, **kwargs + ) + + md: Any = MyDocumentWithDouble() + with raises(ValidationException): + md.save(using="mock") + assert md.a_double == 3.14159265359