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

fix: account for None in error field of http response #512

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adrianAzoitei
Copy link

Description

When the error field in the REST response is null (None for the python client), assume a successful execution.

From the docs:

If query failed, the error attribute contains a QueryError object. That object contains a message, an errorCode and other information about the error. See the io.trino.client.QueryError class in module trino-client in the client directory for more details.

queryError | QueryError | Non-null only if the query resulted in an error.

However, sometimes (some versions of Trino) the server returns an HTTP response with the error field present, yet with a None value. Then, an exception is thrown in the client:

Traceback (most recent call last):
  File "/OBFUSCATED/main.py", line 29, in <module>
    main()
  File "/OBFUSCATED/main.py", line 25, in main
    asyncio.run(trino_scraper.start())
  File "/root/.pyenv/versions/3.11.10/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/root/.pyenv/versions/3.11.10/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.pyenv/versions/3.11.10/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/OBFUSCATED/scrapers.py", line 165, in start
    cur.execute(
  File "/OBFUSCATED/.venv/lib/python3.11/site-packages/trino/dbapi.py", line 585, in execute
    self._iterator = iter(self._query.execute())
                          ^^^^^^^^^^^^^^^^^^^^^
  File "/OBFUSCATED/.venv/lib/python3.11/site-packages/trino/client.py", line 814, in execute
    status = self._request.process(response)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/OBFUSCATED/.venv/lib/python3.11/site-packages/trino/client.py", line 619, in process
    raise self._process_error(response["error"], response.get("id"))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/OBFUSCATED/.venv/lib/python3.11/site-packages/trino/client.py", line 584, in _process_error
    error_type = error["errorType"]
                 ~~~~~^^^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

Non-technical explanation

Sometimes (some versions of Trino) the server returns an HTTP response with the error field present, yet with a None value.

Release notes

(x) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

Fixes #511

Copy link

cla-bot bot commented Jan 6, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

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

Successfully merging this pull request may close these issues.

Uncaught exception when error field is None
1 participant