Skip to content

Commit

Permalink
Merge branch 'master' of github.com:materialsvirtuallab/monty
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyue Ping Ong committed Sep 7, 2023
2 parents 5960521 + dc61002 commit 7e52e52
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
6 changes: 1 addition & 5 deletions monty/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +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,
serialization=core_schema.plain_serializer_function_ser_schema(lambda instance: instance.as_dict()),
)
return core_schema.json_or_python_schema(json_schema=s, python_schema=s)

@classmethod
def _generic_json_schema(cls):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,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": {
Expand All @@ -670,7 +670,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",
Expand Down

0 comments on commit 7e52e52

Please sign in to comment.