Skip to content
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

query_api.query_raw does not return str but urllib3.response.HTTPResponse object #569

Open
anatastor opened this issue Mar 29, 2023 · 6 comments · May be fixed by #606
Open

query_api.query_raw does not return str but urllib3.response.HTTPResponse object #569

anatastor opened this issue Mar 29, 2023 · 6 comments · May be fixed by #606

Comments

@anatastor
Copy link

Hi,

I just learned that the query_api.query_raw () does not return a str as written in the documentation bus instead an urllib3.response.HTTPResponse object, from which the resulting str can be fetched.
I would appreciate either updating the documentation or the function to actually returning a str

@jules-ch
Copy link
Contributor

I've encountered this only on the sync client, the async client returns str as per the docs.

@powersj
Copy link
Contributor

powersj commented Aug 22, 2023

@ivankudibal - is this just a doc update for the sync client?

@jules-ch
Copy link
Contributor

Per the doc both sync and async should return a str representation of the CSV from the response

@jules-ch
Copy link
Contributor

Execute synchronous Flux query and return result as raw unprocessed result as a str.

@jules-ch
Copy link
Contributor

jules-ch commented Aug 22, 2023

the sync QueryAPI:

    def query_raw(self, query: str, org=None, dialect=_BaseQueryApi.default_dialect, params: dict = None):
        """
        Execute synchronous Flux query and return result as raw unprocessed result as a str.

        :param query: a Flux query
        :param str, Organization org: specifies the organization for executing the query;
                                      Take the ``ID``, ``Name`` or ``Organization``.
                                      If not specified the default value from ``InfluxDBClient.org`` is used.
        :param dialect: csv dialect format
        :param params: bind parameters
        :return: str
        """
        org = self._org_param(org)
        result = self._query_api.post_query(org=org, query=self._create_query(query, dialect, params), async_req=False,
                                            _preload_content=False)

        return result

The Async one:

    async def query_raw(self, query: str, org=None, dialect=_BaseQueryApi.default_dialect, params: dict = None):
        """
        Execute asynchronous Flux query and return result as raw unprocessed result as a str.

        :param query: a Flux query
        :param str, Organization org: specifies the organization for executing the query;
                                      Take the ``ID``, ``Name`` or ``Organization``.
                                      If not specified the default value from ``InfluxDBClientAsync.org`` is used.
        :param dialect: csv dialect format
        :param params: bind parameters
        :return: :class:`~str`
        """
        org = self._org_param(org)
        result = await self._post_query(org=org, query=self._create_query(query, dialect, params))
        raw_bytes = await result.read()
        return raw_bytes.decode(_UTF_8_encoding)

In the sync one, the response should also be read and decoded as UTF8 just like the async version.
I can submit a PR if needed.

@powersj
Copy link
Contributor

powersj commented Aug 22, 2023

I can submit a PR if needed.

Please do :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants