Skip to content

Commit d515488

Browse files
authored
fix: HTTP request return type for Management API [async/await] (#531)
1 parent 0927944 commit d515488

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Bug Fixes
44
1. [#526](https://github.com/influxdata/influxdb-client-python/pull/526): Creating client instance from static configuration
5+
1. [#531](https://github.com/influxdata/influxdb-client-python/pull/531): HTTP request return type for Management API [async/await]
56

67
### CI
78
1. [#523](https://github.com/influxdata/influxdb-client-python/pull/523): Add Python 3.11 to CI builds

Diff for: examples/asynchronous_management.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async def main():
1010
organizations_service = OrganizationsService(api_client=client.api_client)
1111

1212
# Find organization with name 'my-org'
13-
organizations = await organizations_service.get_orgs(org='my-org')
13+
organizations = await organizations_service.get_orgs_async(org='my-org')
1414
for organization in organizations.orgs:
1515
print(f'name: {organization.name}, id: {organization.id}')
1616

Diff for: influxdb_client/_async/api_client.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ async def __call_api(
186186
else:
187187
return_data = None
188188

189-
if _return_http_data_only:
190-
return (return_data)
189+
if _return_http_data_only is not False:
190+
return return_data
191191
else:
192192
return (return_data, response_data.status,
193193
response_data.getheaders())
@@ -654,7 +654,7 @@ def __deserialize_model(self, data, klass):
654654

655655
async def _signin(self, resource_path: str):
656656
if _requires_create_user_session(self.configuration, self.cookie, resource_path):
657-
http_info = await SigninService(self).post_signin_async()
657+
http_info = await SigninService(self).post_signin_async(_return_http_data_only=False)
658658
self.cookie = http_info[2]['set-cookie']
659659

660660
async def _signout(self):

Diff for: influxdb_client/client/delete_api_async.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ async def delete(self, start: Union[str, datetime], stop: Union[str, datetime],
3333
org_param = get_org_query_param(org=org, client=self._influxdb_client, required_id=False)
3434

3535
response = await self._service.post_delete_async(delete_predicate_request=predicate_request, bucket=bucket,
36-
org=org_param)
36+
org=org_param, _return_http_data_only=False)
3737
return response[1] == 204

Diff for: influxdb_client/client/write_api_async.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,6 @@ async def write(self, bucket: str, org: str = None,
120120
body = b'\n'.join(payloads[write_precision])
121121
response = await self._write_service.post_write_async(org=org, bucket=bucket, body=body,
122122
precision=write_precision, async_req=False,
123-
content_encoding="identity",
123+
content_encoding="identity", _return_http_data_only=False,
124124
content_type="text/plain; charset=utf-8")
125125
return response[1] == 204

Diff for: tests/test_InfluxDBClientAsync.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pytest
99
from aioresponses import aioresponses
1010

11-
from influxdb_client import Point, WritePrecision, BucketsService
11+
from influxdb_client import Point, WritePrecision, BucketsService, OrganizationsService, Organizations
1212
from influxdb_client.client.exceptions import InfluxDBError
1313
from influxdb_client.client.influxdb_client_async import InfluxDBClientAsync
1414
from influxdb_client.client.query_api import QueryOptions
@@ -329,7 +329,7 @@ async def test_query_and_debug(self):
329329
self.assertIn("my-bucket", results)
330330
# Bucket API
331331
buckets_service = BucketsService(api_client=self.client.api_client)
332-
results = await buckets_service.get_buckets()
332+
results = await buckets_service.get_buckets_async()
333333
self.assertIn("my-bucket", list(map(lambda bucket: bucket.name, results.buckets)))
334334

335335
@async_test
@@ -402,6 +402,13 @@ async def test_parse_utf8_two_bytes_character(self, mocked):
402402
data_frame = await self.client.query_api().query_data_frame("from()", "my-org")
403403
self.assertEqual(1000, len(data_frame))
404404

405+
@async_test
406+
async def test_management_apis(self):
407+
service = OrganizationsService(api_client=self.client.api_client)
408+
results = await service.get_orgs_async()
409+
self.assertIsInstance(results, Organizations)
410+
self.assertIn("my-org", list(map(lambda org: org.name, results.orgs)))
411+
405412
async def _prepare_data(self, measurement: str):
406413
_point1 = Point(measurement).tag("location", "Prague").field("temperature", 25.3)
407414
_point2 = Point(measurement).tag("location", "New York").field("temperature", 24.3)

0 commit comments

Comments
 (0)