diff --git a/databases/.example.env b/databases/.example.env index 4b3e345b2..d5415d5ad 100644 --- a/databases/.example.env +++ b/databases/.example.env @@ -2,5 +2,5 @@ SQLITE_URL='file:dev.db' POSTGRESQL_URL='REPLACE_ME' -MYSQL_URL = 'mysql://prismabot@localhost:3306/prisma_py' +MYSQL_URL='mysql://prismabot@localhost:3306/prisma_py' MARIADB_URL='mysql://root:prisma@localhost:3308/prisma?connect_timeout=20&socket_timeout=60' diff --git a/databases/tests/test_parallel.py b/databases/tests/test_parallel.py new file mode 100644 index 000000000..93f7903af --- /dev/null +++ b/databases/tests/test_parallel.py @@ -0,0 +1,13 @@ +import pytest +import asyncio + +from prisma import Prisma + + +@pytest.mark.asyncio +async def test_count(client: Prisma) -> None: + """Basic usage with a result""" + await client.post.create({'title': 'post 1', 'published': False}) + promises = [client.post.count() for _ in range(1000)] + results = await asyncio.gather(*promises) + assert all(result == 1 for result in results) diff --git a/src/prisma/_async_http.py b/src/prisma/_async_http.py index 615b01bf8..0a8f92545 100644 --- a/src/prisma/_async_http.py +++ b/src/prisma/_async_http.py @@ -23,7 +23,8 @@ async def download(self, url: str, dest: str) -> None: @override async def request(self, method: Method, url: str, **kwargs: Any) -> 'Response': - return Response(await self.session.request(method, url, **kwargs)) + async with httpx.AsyncClient(**self.session_kwargs) as session: + return Response(await session.request(method, url, **kwargs)) @override def open(self) -> None: