Skip to content

Incorrect error message with async client #511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tlebrize opened this issue Oct 7, 2022 · 3 comments · Fixed by #512
Closed

Incorrect error message with async client #511

tlebrize opened this issue Oct 7, 2022 · 3 comments · Fixed by #512
Labels
bug Something isn't working
Milestone

Comments

@tlebrize
Copy link

tlebrize commented Oct 7, 2022

Specifications

  • Client Version: 1.32.0 (async)
  • InfluxDB Version: v2.4.0
  • Platform: Ubuntu 22.04
  • Python: 3.10.7

Code sample to reproduce problem

from influxdb_client.client.influxdb_client_async import InfluxDBClientAsync

QUERY = '''
import "sampledata"
sampledata.float()
'''

async def test():
    client = InfluxDBClientAsync(
        url=settings.INFLUX_SERVER,
        token="oops",
        org=settings.INFLUX_ORG,
        verify_ssl="true",
    )

    print(await client.ping())
    # True

    query_api = client.query_api()
    print(await query_api.query(QUERY))
    # Raises : "FluxCsvParserException: Unable to parse CSV response. FluxTable definition was not found."

Expected behavior

the call to query should raise an APIError:

ApiException: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Date': 'Fri, 07 Oct 2022 09:36:10 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '55', 'Connection': 'keep-alive', 'X-Influxdb-Build': 'OSS', 'X-Influxdb-Version': 'v2.4.0', 'X-Platform-Error-Code': 'unauthorized', 'Strict-Transport-Security': 'max-age=15724800; includeSubDomains'})
HTTP response body: b'{"code":"unauthorized","message":"unauthorized access"}'

While not perfect, this is what happens with the sync client.

Actual behavior

the call to query raises this instead :

"FluxCsvParserException: Unable to parse CSV response. FluxTable definition was not found."

Full traceback:

FluxCsvParserException                    Traceback (most recent call last)
Cell In [2], line 22
     19     print(await query_api.query(QUERY))
     20     client.close()
---> 22 await test()

Cell In [2], line 19, in test()
     17 print(await client.ping())
     18 query_api = client.query_api()
---> 19 print(await query_api.query(QUERY))
     20 client.close()

File ~/.pyenv/versions/3.10.6/envs/lib/python3.10/site-packages/influxdb_client/client/query_api_async.py:106, in QueryApiAsync.query(self, query, org, params)
     99 org = self._org_param(org)
    101 response = await self._query_api.post_query_async(org=org,
    102                                                   query=self._create_query(query, self.default_dialect, params),
    103                                                   async_req=False, _preload_content=False,
    104                                                   _return_http_data_only=True)
--> 106 return await self._to_tables_async(response, query_options=self._get_query_options())

File ~/.pyenv/versions/3.10.6/envs/lib/python3.10/site-packages/influxdb_client/client/_base.py:308, in _BaseQueryApi._to_tables_async(self, response, query_options, response_metadata_mode)
    302 """
    303 Parse HTTP response to TableList.
    304 
    305 :param response: HTTP response from an HTTP client. Expected type: `aiohttp.client_reqrep.ClientResponse`.
    306 """
    307 async with self._to_tables_parser(response, query_options, response_metadata_mode) as parser:
--> 308     async for _ in parser.generator_async():
    309         pass
    310     return parser.table_list()

File ~/.pyenv/versions/3.10.6/envs/lib/python3.10/site-packages/influxdb_client/client/flux_csv_parser.py:146, in FluxCsvParser._parse_flux_response_async(self)
    144     csv = list(csv_parser.reader([line.decode(_UTF_8_encoding)]))
    145     if len(csv) >= 1:
--> 146         for val in self._parse_flux_response_row(metadata, csv[0]):
    147             yield val
    149 # Return latest DataFrame

File ~/.pyenv/versions/3.10.6/envs/lib/python3.10/site-packages/influxdb_client/client/flux_csv_parser.py:192, in FluxCsvParser._parse_flux_response_row(self, metadata, csv)
    190     metadata.table_id = -1
    191 elif metadata.table is None:
--> 192     raise FluxCsvParserException(
    193         "Unable to parse CSV response. FluxTable definition was not found."
    194     )
    196 #  # datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string,string
    197 if ANNOTATION_DATATYPE == token:

FluxCsvParserException: Unable to parse CSV response. FluxTable definition was not found.

Additional info

This exception is raised whenever anything goes wrong, from a flux syntax error to a connection issue. While not a problem during normal use, it makes development with the async API very frustrating.

@tlebrize tlebrize added the bug Something isn't working label Oct 7, 2022
@bednar
Copy link
Contributor

bednar commented Oct 7, 2022

Hi @tlebrize,

thanks for using our client.

I will take a look and prepare fix ASAP, stay tuned...

Regards

@bednar
Copy link
Contributor

bednar commented Oct 7, 2022

Hi @tlebrize,

I have prepared a fixed version within #512. Development version of the client will be available after #512 acceptance, stable version in regular release cycle.

You could use a fixed version by:

pip install git+https://github.com/influxdata/influxdb-client-python.git@async-exception-query-propagation

Regards

@tlebrize
Copy link
Author

tlebrize commented Oct 7, 2022

Thanks for the quick fix @bednar !

@bednar bednar added this to the 1.34.0 milestone Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants