Skip to content

Commit

Permalink
fix: HTTP request return type for Management API [async/await] (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar authored Nov 10, 2022
1 parent 0927944 commit d515488
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

### CI
1. [#523](https://github.com/influxdata/influxdb-client-python/pull/523): Add Python 3.11 to CI builds
Expand Down
2 changes: 1 addition & 1 deletion examples/asynchronous_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async def main():
organizations_service = OrganizationsService(api_client=client.api_client)

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

Expand Down
6 changes: 3 additions & 3 deletions influxdb_client/_async/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ async def __call_api(
else:
return_data = None

if _return_http_data_only:
return (return_data)
if _return_http_data_only is not False:
return return_data
else:
return (return_data, response_data.status,
response_data.getheaders())
Expand Down Expand Up @@ -654,7 +654,7 @@ def __deserialize_model(self, data, klass):

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

async def _signout(self):
Expand Down
2 changes: 1 addition & 1 deletion influxdb_client/client/delete_api_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ async def delete(self, start: Union[str, datetime], stop: Union[str, datetime],
org_param = get_org_query_param(org=org, client=self._influxdb_client, required_id=False)

response = await self._service.post_delete_async(delete_predicate_request=predicate_request, bucket=bucket,
org=org_param)
org=org_param, _return_http_data_only=False)
return response[1] == 204
2 changes: 1 addition & 1 deletion influxdb_client/client/write_api_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ async def write(self, bucket: str, org: str = None,
body = b'\n'.join(payloads[write_precision])
response = await self._write_service.post_write_async(org=org, bucket=bucket, body=body,
precision=write_precision, async_req=False,
content_encoding="identity",
content_encoding="identity", _return_http_data_only=False,
content_type="text/plain; charset=utf-8")
return response[1] == 204
11 changes: 9 additions & 2 deletions tests/test_InfluxDBClientAsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest
from aioresponses import aioresponses

from influxdb_client import Point, WritePrecision, BucketsService
from influxdb_client import Point, WritePrecision, BucketsService, OrganizationsService, Organizations
from influxdb_client.client.exceptions import InfluxDBError
from influxdb_client.client.influxdb_client_async import InfluxDBClientAsync
from influxdb_client.client.query_api import QueryOptions
Expand Down Expand Up @@ -329,7 +329,7 @@ async def test_query_and_debug(self):
self.assertIn("my-bucket", results)
# Bucket API
buckets_service = BucketsService(api_client=self.client.api_client)
results = await buckets_service.get_buckets()
results = await buckets_service.get_buckets_async()
self.assertIn("my-bucket", list(map(lambda bucket: bucket.name, results.buckets)))

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

@async_test
async def test_management_apis(self):
service = OrganizationsService(api_client=self.client.api_client)
results = await service.get_orgs_async()
self.assertIsInstance(results, Organizations)
self.assertIn("my-org", list(map(lambda org: org.name, results.orgs)))

async def _prepare_data(self, measurement: str):
_point1 = Point(measurement).tag("location", "Prague").field("temperature", 25.3)
_point2 = Point(measurement).tag("location", "New York").field("temperature", 24.3)
Expand Down

0 comments on commit d515488

Please sign in to comment.