-
Notifications
You must be signed in to change notification settings - Fork 38
Description
Description
When calling the smartquery method in the Datasource class with a POST request, a TypeError occurs because the code incorrectly tries to await the POST method itself rather than calling it.
Expected Behavior
The code should properly call the async POST method of the client when processing a POST request, not try to await the method object itself.
Actual Behavior
The code raises:
TypeError: object function can't be used in 'await' expression
Steps to Reproduce
- Call
smartquerymethod with a request dictionary containing"method": "POST" - The error occurs when trying to assign
send_request = await self.client.POST
Environment
- Python: 3.11
- OS: MacOS Ventura
- Package: grafana-client
Root Cause
The issue is in the async smartquery method where it incorrectly tries to await the method object rather than calling it:
python
if request["method"] == "POST":
send_request = await self.client.POST # This is wrong
else:
send_request = await self.client.GET # This is wrong
Proposed Fix
The code should assign the method reference without awaiting it, and then call it later:
python
if request["method"] == "POST":
send_request = self.client.POST # Remove await
else:
send_request = self.client.GET # Remove await
Then later when actually making the request:
return await send_request(url, request_kwargs)
Additional Context
The same pattern is correctly implemented in other parts of the code, like where it handles the special case for Elasticsearch/Testdata:
python
send_request = await self.client.GET # This should also be fixed similarly
Workaround
None currently available without modifying the source code.