Skip to content

Commit d9f3f64

Browse files
JIAQIAamotl
authored andcommitted
fix(async): correct async POST/GET method handling in smartquery
This fixes a TypeError that occurred when trying to await HTTP method references instead of properly calling them. The changes: 1. Remove incorrect `await` when assigning POST/GET method references 2. Add proper `await` when actually making the request The bug prevented successful POST requests in the async datasource query functionality.
1 parent 7acc4d8 commit d9f3f64

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

grafana_client/elements/_async/datasource.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,9 @@ async def smartquery(
353353
# Compute request method, body, and endpoint.
354354
if "method" in request and isinstance(request["method"], str):
355355
if request["method"] == "POST":
356-
send_request = await self.client.POST
356+
send_request = self.client.POST
357357
else:
358-
send_request = await self.client.GET
358+
send_request = self.client.GET
359359

360360
logger.info(f"Submitting request: {request}")
361361

@@ -378,7 +378,7 @@ async def smartquery(
378378
database_name=datasource.get("database"),
379379
)
380380
request_kwargs = {}
381-
send_request = await self.client.GET
381+
send_request = self.client.GET
382382

383383
elif datasource_type in ("prometheus", "loki") and Version(await self.api.version) <= VERSION_7:
384384
if (
@@ -411,7 +411,7 @@ async def smartquery(
411411

412412
# Submit query.
413413
try:
414-
return send_request(url, **request_kwargs)
414+
return await send_request(url, **request_kwargs)
415415
except (GrafanaClientError, GrafanaServerError) as ex:
416416
logger.error(
417417
f"Querying data source failed. id={datasource_id}, type={datasource_type}. "

0 commit comments

Comments
 (0)