diff --git a/robot-server/robot_server/persistence/pydantic.py b/robot-server/robot_server/persistence/pydantic.py index 184cd3bf8c82..bf2b7b0a3ae0 100644 --- a/robot-server/robot_server/persistence/pydantic.py +++ b/robot-server/robot_server/persistence/pydantic.py @@ -20,7 +20,7 @@ def pydantic_to_json(obj: BaseModel) -> str: def pydantic_list_to_json(obj_list: Sequence[BaseModel]) -> str: """Serialize a list of Pydantic objects for storing in the SQL database.""" - return json.dumps([obj.dict(by_alias=True, exclude_none=True) for obj in obj_list]) + return json.dumps([obj.model_dump(by_alias=True, exclude_none=True) for obj in obj_list]) # TODO: It would be nice to type this function as (Type[_BasemodelT] | TypeAdapter[_BaseModelT]) -> _BaseModelT, diff --git a/robot-server/robot_server/service/errors.py b/robot-server/robot_server/service/errors.py index 94a8d758563a..8503b7672581 100644 --- a/robot-server/robot_server/service/errors.py +++ b/robot-server/robot_server/service/errors.py @@ -79,7 +79,7 @@ def __init__( *wrapped_details, ), links=links, - ).dict(exclude_none=True) + ).model_dump(exclude_none=True) super().__init__( status_code=definition.status_code, diff --git a/robot-server/robot_server/service/legacy/routers/networking.py b/robot-server/robot_server/service/legacy/routers/networking.py index b47cf283ddfa..ea3c4543ea84 100644 --- a/robot-server/robot_server/service/legacy/routers/networking.py +++ b/robot-server/robot_server/service/legacy/routers/networking.py @@ -90,7 +90,7 @@ async def get_wifi_networks( "letting the system decide when to do a rescan." ), ), - ] = False + ] = False, ) -> WifiNetworks: networks = await nmcli.available_ssids(rescan) return WifiNetworks(list=[WifiNetworkFull(**n) for n in networks]) @@ -190,7 +190,7 @@ async def post_wifi_key(key: UploadFile = File(...)): else: # We return a JSONResponse because we want the 200 status code. response.message = "Key file already present" - return JSONResponse(content=response.dict()) + return JSONResponse(content=response.model_dump()) @router.delete( @@ -210,7 +210,7 @@ async def delete_wifi_key( description="The ID of key to delete, as determined by a previous" " call to GET /wifi/keys", ), - ] + ], ) -> V1BasicResponse: """Delete wifi key handler""" deleted_file = wifi.remove_key(key_uuid) @@ -274,4 +274,4 @@ async def post_wifi_disconnect(wifi_ssid: WifiNetwork): ) else: stat = status.HTTP_500_INTERNAL_SERVER_ERROR - return JSONResponse(status_code=stat, content=result.dict()) + return JSONResponse(status_code=stat, content=result.model_dump()) diff --git a/robot-server/robot_server/service/session/command_execution/callable_executor.py b/robot-server/robot_server/service/session/command_execution/callable_executor.py index 39a62cbe3ae2..2503ff952e3b 100644 --- a/robot-server/robot_server/service/session/command_execution/callable_executor.py +++ b/robot-server/robot_server/service/session/command_execution/callable_executor.py @@ -26,7 +26,7 @@ async def execute(self, command: Command) -> CompletedCommand: with duration() as time_it: name_arg = command.request.command data = command.request.data - data_arg = data.dict() if data else {} + data_arg = data.model_dump() if data else {} await self._callable(name_arg, data_arg) diff --git a/robot-server/tests/service/json_api/test_request.py b/robot-server/tests/service/json_api/test_request.py index de93182dc7d4..8c2012b158be 100644 --- a/robot-server/tests/service/json_api/test_request.py +++ b/robot-server/tests/service/json_api/test_request.py @@ -10,14 +10,14 @@ def test_attributes_as_dict(): DictRequest = RequestModel[dict] obj_to_validate = {"data": {"some_data": 1}} my_request_obj = DictRequest.model_validate(obj_to_validate) - assert my_request_obj.dict() == {"data": {"some_data": 1}} + assert my_request_obj.model_dump() == {"data": {"some_data": 1}} def test_attributes_as_item_model(): ItemRequest = RequestModel[ItemModel] obj_to_validate = {"data": {"name": "apple", "quantity": 10, "price": 1.20}} my_request_obj = ItemRequest.model_validate(obj_to_validate) - assert my_request_obj.dict() == obj_to_validate + assert my_request_obj.model_dump() == obj_to_validate def test_attributes_as_item_model_empty_dict(): @@ -91,6 +91,6 @@ def test_request_with_id(): "data": {"type": "item", "attributes": {}, "id": "abc123"}, } my_request_obj = MyRequest.model_validate(obj_to_validate) - assert my_request_obj.dict() == { + assert my_request_obj.model_dump() == { "data": {"type": "item", "attributes": {}, "id": "abc123"}, } diff --git a/robot-server/tests/service/json_api/test_resource_links.py b/robot-server/tests/service/json_api/test_resource_links.py index a0bf07d290e7..581c018892ad 100644 --- a/robot-server/tests/service/json_api/test_resource_links.py +++ b/robot-server/tests/service/json_api/test_resource_links.py @@ -15,7 +15,7 @@ def test_follows_structure(): } } validated = ThingWithLink.model_validate(structure_to_validate) - assert validated.dict() == structure_to_validate + assert validated.model_dump() == structure_to_validate def test_must_be_self_key_with_string_value(): diff --git a/robot-server/tests/service/json_api/test_response.py b/robot-server/tests/service/json_api/test_response.py index 6952468229bb..05e01f45b6c4 100644 --- a/robot-server/tests/service/json_api/test_response.py +++ b/robot-server/tests/service/json_api/test_response.py @@ -126,4 +126,4 @@ class ResponseSpec(NamedTuple): @pytest.mark.parametrize(ResponseSpec._fields, RESPONSE_SPECS) def test_response_to_dict(subject: BaseModel, expected: Dict[str, Any]) -> None: - assert subject.dict() == expected + assert subject.model_dump() == expected diff --git a/system-server/system_server/settings/settings.py b/system-server/system_server/settings/settings.py index d7b90658e8ff..5256a1e09e1a 100644 --- a/system-server/system_server/settings/settings.py +++ b/system-server/system_server/settings/settings.py @@ -77,7 +77,7 @@ def save_settings(settings: SystemServerSettings) -> bool: env_path = env_path or f"{settings.persistence_directory}/system.env" prefix = settings.model_config.get("env_prefix") try: - for key, val in settings.dict().items(): + for key, val in settings.model_dump().items(): name = f"{prefix}{key}" value = str(val) if val is not None else "" set_key(env_path, name, value)