From ac4b73c5a8eedde509570b54f660ff25cf20f558 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 6 Sep 2023 17:15:13 -0700 Subject: [PATCH 1/4] Remove setting pydantic core serialization --- monty/json.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/monty/json.py b/monty/json.py index 0784735bd..4b353172c 100644 --- a/monty/json.py +++ b/monty/json.py @@ -279,9 +279,7 @@ def __get_pydantic_core_schema__(cls, source_type, handler): return core_schema.json_or_python_schema( json_schema=s, - python_schema=s, - serialization=core_schema.plain_serializer_function_ser_schema(lambda instance: instance.as_dict()), - ) + python_schema=s) @classmethod def _generic_json_schema(cls): From 0415be664abafa20bbaa6c34b9e0c24a8534bf17 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 6 Sep 2023 17:29:08 -0700 Subject: [PATCH 2/4] Test pydantic with full set of jsanitize args --- tests/test_json.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_json.py b/tests/test_json.py index 3ba91a167..41e44ca9f 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -649,7 +649,7 @@ class ModelWithMSONable(BaseModel): test_dict_object = ModelWithMSONable(a=test_object.a.as_dict()) assert test_dict_object.a.a == test_object.a.a - assert test_object.schema() == { + assert test_object.model_json_schema() == { "title": "ModelWithMSONable", "type": "object", "properties": { @@ -667,7 +667,7 @@ class ModelWithMSONable(BaseModel): "required": ["a"], } - d = jsanitize(test_object, strict=True) + d = jsanitize(test_object, strict=True, enum_values=True, allow_bson=True) assert d == { "a": { "@module": "tests.test_json", From 6a9e756807b1a8e016f55f881ca1f896b1eb2543 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 7 Sep 2023 17:40:13 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- monty/json.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/monty/json.py b/monty/json.py index 4b353172c..3b27dd70a 100644 --- a/monty/json.py +++ b/monty/json.py @@ -277,9 +277,7 @@ def __get_pydantic_core_schema__(cls, source_type, handler): s = core_schema.general_plain_validator_function(cls.validate_monty_v2) - return core_schema.json_or_python_schema( - json_schema=s, - python_schema=s) + return core_schema.json_or_python_schema(json_schema=s, python_schema=s) @classmethod def _generic_json_schema(cls): From 8ddce9048d1c25ff1b22a11e254d43e53e38bcc9 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 7 Sep 2023 10:44:10 -0700 Subject: [PATCH 4/4] Linting --- monty/json.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/monty/json.py b/monty/json.py index 4b353172c..3b27dd70a 100644 --- a/monty/json.py +++ b/monty/json.py @@ -277,9 +277,7 @@ def __get_pydantic_core_schema__(cls, source_type, handler): s = core_schema.general_plain_validator_function(cls.validate_monty_v2) - return core_schema.json_or_python_schema( - json_schema=s, - python_schema=s) + return core_schema.json_or_python_schema(json_schema=s, python_schema=s) @classmethod def _generic_json_schema(cls):