Skip to content

Bug Report: TypeError in async smartquery method when using POST request #223

@JIAQIA

Description

@JIAQIA

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

  1. Call smartquery method with a request dictionary containing "method": "POST"
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions