Skip to content

Commit

Permalink
Update other uses of .json, .copy, .schema
Browse files Browse the repository at this point in the history
  • Loading branch information
TheByronHimes committed Oct 10, 2023
1 parent 045247f commit b794a16
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/hexkit/protocols/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def _validate_dto_model_id(cls, *, dto_model: type[Dto], id_field: str) -> None:
"""Checks whether the dto_model contains the expected id_field.
Raises IdFieldNotFoundError otherwise.
"""
if id_field not in dto_model.schema()["properties"]:
if id_field not in dto_model.model_json_schema()["properties"]:
raise cls.IdFieldNotFoundError()

@classmethod
Expand All @@ -306,11 +306,11 @@ def _validate_dto_creation_model(
if dto_creation_model is None:
return

expected_properties = copy(dto_model.schema()["properties"])
expected_properties = copy(dto_model.model_json_schema()["properties"])
# (the schema method returns an attribute of the class, making a copy to not
# alter the class)
del expected_properties[id_field]
observed_properties = dto_creation_model.schema()["properties"]
observed_properties = dto_creation_model.model_json_schema()["properties"]

if observed_properties != expected_properties:
raise cls.CreationModelInvalidError()
Expand Down
2 changes: 1 addition & 1 deletion src/hexkit/providers/mongodb/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _dto_to_document(self, dto: Dto) -> dict[str, Any]:
"""Converts a DTO into a representation that is compatible documents for a
MongoDB Database.
"""
document = json.loads(dto.json())
document = json.loads(dto.model_dump_json())
document["_id"] = document.pop(self._id_field)

return document
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ async def test_dao_happy(mongodb_fixture: MongoDbFixture): # noqa: F811
assert resource_read == resource_inserted

# update the resource:
resource_update = resource_inserted.copy(update={"field_c": False})
resource_update = resource_inserted.model_copy(update={"field_c": False})
await dao.update(resource_update)

# read the updated resource again:
Expand Down Expand Up @@ -241,7 +241,7 @@ async def test_dao_upsert_natural_id_happy(
assert resource == resource_observed

# update the resource:
resource_update = resource.copy(update={"field_c": False})
resource_update = resource.model_copy(update={"field_c": False})
await dao.upsert(resource_update)

# check the updated resource:
Expand Down

0 comments on commit b794a16

Please sign in to comment.