Skip to content

Commit 72699c8

Browse files
committed
Remove .dict() occurrences
1 parent 7da5dec commit 72699c8

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

domains/books/_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async def create_book(self, book: BookData) -> Book:
2626
# Using processes could be better, but it would bring technical complexity
2727
# https://anyio.readthedocs.io/en/3.x/subprocesses.html#running-functions-in-worker-processes
2828
book_data_altered = await to_thread.run_sync(
29-
some_cpu_intensive_blocking_task, book.dict()
29+
some_cpu_intensive_blocking_task, book.model_dump()
3030
)
3131
book_model = BookModel(**book_data_altered)
3232
return Book.model_validate(

grpc_app/servicers/books.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ async def ListBooks(
1414
book_service = BookService()
1515
return books_messages.ListBooksResponse(
1616
books=[
17-
books_messages.Book(**x.dict()) for x in await book_service.list_books()
17+
books_messages.Book(**x.model_dump())
18+
for x in await book_service.list_books()
1819
]
1920
)

http_app/routes/api/books.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ async def create_book(
4949
data: CreateBookRequest,
5050
) -> CreateBookResponse:
5151
book_service = BookService()
52-
created_book = await book_service.create_book(book=BookData(**data.dict()))
52+
created_book = await book_service.create_book(
53+
book=BookData.model_validate(data, from_attributes=True)
54+
)
5355
return CreateBookResponse(book=created_book)
5456

5557

@@ -59,5 +61,7 @@ async def create_book_v2(
5961
some_optional_query_param: bool = False,
6062
) -> CreateBookResponse:
6163
book_service = BookService()
62-
created_book = await book_service.create_book(book=BookData(**data.dict()))
64+
created_book = await book_service.create_book(
65+
book=BookData.model_validate(data, from_attributes=True)
66+
)
6367
return CreateBookResponse(book=created_book)

http_app/routes/graphql/resolvers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
async def list_books():
55
book_service = BookService()
66
books = await book_service.list_books()
7-
return [Book(**x.dict()) for x in books]
7+
return [Book.model_validate(x, from_attributes=True) for x in books]

tests/http_app/routes/books/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def book_service() -> Iterator[MagicMock]:
1414
svc = MagicMock(autospec=BookService)
1515
svc.create_book = AsyncMock(
16-
side_effect=lambda book: Book(book_id=randint(1, 1000), **book.dict())
16+
side_effect=lambda book: Book(book_id=randint(1, 1000), **book.model_dump())
1717
)
1818
svc.list_books = AsyncMock(
1919
return_value=[

0 commit comments

Comments
 (0)