diff --git a/src/aleph/chains/chain_data_service.py b/src/aleph/chains/chain_data_service.py index 7eadf1af..2589f5d1 100644 --- a/src/aleph/chains/chain_data_service.py +++ b/src/aleph/chains/chain_data_service.py @@ -166,7 +166,9 @@ def _get_tx_messages_smart_contract_protocol(tx: ChainTxDb) -> List[Dict[str, An ) try: - payload = cast(GenericMessageEvent, payload_model.parse_obj(tx.content)) + payload = cast( + GenericMessageEvent, payload_model.model_validate(tx.content) + ) except ValidationError: raise InvalidContent(f"Incompatible tx content for {tx.chain}/{tx.hash}") diff --git a/src/aleph/chains/indexer_reader.py b/src/aleph/chains/indexer_reader.py index c27d5ba4..dab32b22 100644 --- a/src/aleph/chains/indexer_reader.py +++ b/src/aleph/chains/indexer_reader.py @@ -147,7 +147,7 @@ async def _query(self, query: str, model: Type[T]) -> T: response = await self.http_session.post("/", json={"query": query}) response.raise_for_status() response_json = await response.json() - return model.parse_obj(response_json) + return model.model_validate(response_json) async def fetch_account_state( self, diff --git a/src/aleph/chains/tezos.py b/src/aleph/chains/tezos.py index 59f5690a..c98f5c8f 100644 --- a/src/aleph/chains/tezos.py +++ b/src/aleph/chains/tezos.py @@ -162,7 +162,7 @@ async def fetch_messages( response.raise_for_status() response_json = await response.json() - return IndexerResponse[IndexerMessageEvent].parse_obj(response_json) + return IndexerResponse[IndexerMessageEvent].model_validate(response_json) def indexer_event_to_chain_tx( diff --git a/src/aleph/db/models/messages.py b/src/aleph/db/models/messages.py index 11913450..eb06ae12 100644 --- a/src/aleph/db/models/messages.py +++ b/src/aleph/db/models/messages.py @@ -61,7 +61,7 @@ def validate_message_content( content_dict: Dict[str, Any], ) -> BaseContent: content_type = CONTENT_TYPE_MAP[message_type] - content = content_type.parse_obj(content_dict) + content = content_type.model_validate(content_dict) # Validate that the content time can be converted to datetime. This will # raise a ValueError and be caught # TODO: move this validation in aleph-message diff --git a/src/aleph/schemas/api/messages.py b/src/aleph/schemas/api/messages.py index 5b462008..eb7aaf45 100644 --- a/src/aleph/schemas/api/messages.py +++ b/src/aleph/schemas/api/messages.py @@ -131,7 +131,7 @@ def format_message(message: MessageDb) -> AlephMessage: def format_message_dict(message: Dict[str, Any]) -> AlephMessage: message_type = message.get("type") message_cls = MESSAGE_CLS_DICT[message_type] - return message_cls.parse_obj(message) + return message_cls.model_validate(message) class BaseMessageStatus(BaseModel): diff --git a/src/aleph/schemas/chains/indexer_response.py b/src/aleph/schemas/chains/indexer_response.py index 60ebf540..6081769a 100644 --- a/src/aleph/schemas/chains/indexer_response.py +++ b/src/aleph/schemas/chains/indexer_response.py @@ -44,10 +44,10 @@ class AccountEntityState(BaseModel): processed: List[Tuple[dt.datetime, dt.datetime]] @field_validator("pending", "processed", mode="before") - def split_datetime_ranges(cls, v): - if isinstance(v, str): - return v.split("/") - return v + def split_datetime_ranges(cls, values): + return map( + lambda value: value.split("/") if isinstance(value, str) else value, values + ) class IndexerAccountStateResponseData(BaseModel): diff --git a/src/aleph/web/controllers/accounts.py b/src/aleph/web/controllers/accounts.py index 141b0828..add24534 100644 --- a/src/aleph/web/controllers/accounts.py +++ b/src/aleph/web/controllers/accounts.py @@ -83,7 +83,7 @@ async def get_account_files(request: web.Request) -> web.Response: address = _get_address_from_request(request) try: - query_params = GetAccountFilesQueryParams.parse_obj(request.query) + query_params = GetAccountFilesQueryParams.model_validate(request.query) except ValidationError as e: raise web.HTTPUnprocessableEntity(text=e.json(indent=4)) diff --git a/src/aleph/web/controllers/aggregates.py b/src/aleph/web/controllers/aggregates.py index 1d63847a..66b91085 100644 --- a/src/aleph/web/controllers/aggregates.py +++ b/src/aleph/web/controllers/aggregates.py @@ -38,7 +38,7 @@ async def address_aggregate(request: web.Request) -> web.Response: address: str = request.match_info["address"] try: - query_params = AggregatesQueryParams.parse_obj(request.query) + query_params = AggregatesQueryParams.model_validate(request.query) except ValidationError as e: raise web.HTTPUnprocessableEntity( text=e.json(), content_type="application/json" diff --git a/src/aleph/web/controllers/main.py b/src/aleph/web/controllers/main.py index 7fcb7aa8..5b5c5b79 100644 --- a/src/aleph/web/controllers/main.py +++ b/src/aleph/web/controllers/main.py @@ -98,7 +98,7 @@ async def ccn_metric(request: web.Request) -> web.Response: """Fetch metrics for CCN node id""" session_factory: DbSessionFactory = get_session_factory_from_request(request) - query_params = Metrics.parse_obj(request.query) + query_params = Metrics.model_validate(request.query) node_id = _get_node_id_from_request(request) @@ -124,7 +124,7 @@ async def crn_metric(request: web.Request) -> web.Response: """Fetch Metric for crn.""" session_factory: DbSessionFactory = get_session_factory_from_request(request) - query_params = Metrics.parse_obj(request.query) + query_params = Metrics.model_validate(request.query) node_id = _get_node_id_from_request(request) diff --git a/src/aleph/web/controllers/messages.py b/src/aleph/web/controllers/messages.py index eabf2587..e6e2144a 100644 --- a/src/aleph/web/controllers/messages.py +++ b/src/aleph/web/controllers/messages.py @@ -243,7 +243,7 @@ async def view_messages_list(request: web.Request) -> web.Response: """Messages list view with filters""" try: - query_params = MessageQueryParams.parse_obj(request.query) + query_params = MessageQueryParams.model_validate(request.query) except ValidationError as e: raise web.HTTPUnprocessableEntity(text=e.json(indent=4)) @@ -388,7 +388,7 @@ async def messages_ws(request: web.Request) -> web.WebSocketResponse: mq_channel = await get_mq_ws_channel_from_request(request=request, logger=LOGGER) try: - query_params = WsMessageQueryParams.parse_obj(request.query) + query_params = WsMessageQueryParams.model_validate(request.query) except ValidationError as e: raise web.HTTPUnprocessableEntity(text=e.json(indent=4)) diff --git a/src/aleph/web/controllers/p2p.py b/src/aleph/web/controllers/p2p.py index 88939d72..1229633c 100644 --- a/src/aleph/web/controllers/p2p.py +++ b/src/aleph/web/controllers/p2p.py @@ -125,7 +125,7 @@ class PubMessageRequest(BaseModel): @shielded async def pub_message(request: web.Request): try: - request_data = PubMessageRequest.parse_obj(await request.json()) + request_data = PubMessageRequest.model_validate(await request.json()) except ValidationError as e: raise web.HTTPUnprocessableEntity(text=e.json(indent=4)) except ValueError: diff --git a/src/aleph/web/controllers/posts.py b/src/aleph/web/controllers/posts.py index 2e01da51..fc7b77f2 100644 --- a/src/aleph/web/controllers/posts.py +++ b/src/aleph/web/controllers/posts.py @@ -173,7 +173,7 @@ def merged_post_v0_to_dict( def get_query_params(request: web.Request) -> PostQueryParams: try: - query_params = PostQueryParams.parse_obj(request.query) + query_params = PostQueryParams.model_validate(request.query) except ValidationError as e: raise web.HTTPUnprocessableEntity(text=e.json(indent=4)) @@ -231,7 +231,7 @@ async def view_posts_list_v1(request) -> web.Response: query_string = request.query_string try: - query_params = PostQueryParams.parse_obj(request.query) + query_params = PostQueryParams.model_validate(request.query) except ValidationError as e: raise web.HTTPUnprocessableEntity(text=e.json(indent=4))