-
-
Notifications
You must be signed in to change notification settings - Fork 447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Same path apis with different method and async sync are mixed then all considered as async when testing #1347
Comments
Hi @LeeJB-48 You should use async test client for async views: from ninja.testing import TestAsyncClient
client = TestAsyncClient(router)
response = await client.post("/test/") |
router = Router()
@router.get("/test/")
async def test_get(request):
return {"test": "test"}
@router.post("/test/")
def test_post(request):
return {"test": "test"} then even if /test/ with POST method , then the view for that endpoint is considered "async" view even if that the exact POST method's function is sync? (reason is that the same endpoint for GET method is async?) |
@vitalik same issue here. async GET endpoint: /sales/{sale.id} Here's the test case for the sync PATCH endpoint that gives the error: AttributeError: 'coroutine' object has no attribute
But if i convert my 'test_update_price_b2c' test to async, with sync_to_async for django stuff it works:
But this isn't expected behaviour. I would like to test my sync patch endpoint in a sync way? |
Describe the bug
if same path with different method and async sync are mixed then they are all considered as async when testing
i use async for (GET) operation
and use sync for (POST,DELETE,PUT,PATCH) operations
but i got error when testing
example code is below
and it throws an error says
so i found PathView._async_view from
but i found that both callbacks are all PathView._async_view , even for the sync view (POST method)
and the reason is that when operations are added to Router()
for same path , then even if one operation is async , then all considered async
i'm having a trouble because of that
is this a bug? or is there any purpose for that?
Versions (please complete the following information):
The text was updated successfully, but these errors were encountered: