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

Uncaught exception when error field is None #511

Open
1 task done
adrianAzoitei opened this issue Jan 6, 2025 · 1 comment · May be fixed by #512
Open
1 task done

Uncaught exception when error field is None #511

adrianAzoitei opened this issue Jan 6, 2025 · 1 comment · May be fixed by #512

Comments

@adrianAzoitei
Copy link

Expected behavior

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.

Actual behavior

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

Steps To Reproduce

Not yet sure what causes my Trino installation to give out a None value for the error field in the HTTP response instead of omitting the filed altogether, or even if this is not actually just standard behavior.

What does fix it for me is a simple patch in client.py:

def process(self, http_response) -> TrinoStatus:
   ...
   if "error" in response and response["error"]:
       ...

Log output

No response

Operating System

alpine (container environment)

Trino Python client version

0.331.0

Trino Server version

450

Python version

3.11.0

Are you willing to submit PR?

  • Yes I am willing to submit a PR!
@adrianAzoitei
Copy link
Author

Might be related to #483

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

Successfully merging a pull request may close this issue.

1 participant