trinodb / trino-python-client

Python client for Trino
Apache License 2.0
323 stars 163 forks source link

NoneType Object is Not Subscriptable Error #483

Open vinayakmalik95 opened 1 week ago

vinayakmalik95 commented 1 week ago

Expected behavior

When

def process(self, http_response) -> TrinoStatus:
    if not http_response.ok:
        self.raise_response_error(http_response)

    http_response.encoding = "utf-8"
    response = http_response.json()
    if "error" in response:
        raise self._process_error(response["error"], response.get("id"))

response is a dict so the logic is not correct over here, actually it should be

if response.get("error") is not None:

Actual behavior

if "error" in response: condition in client.py where error is None it gives

Error: NoneType Object is Not Subscriptable Error

Steps To Reproduce

This occur when I am trying to read via python client when activating data for Apache kyuubi where trinofrontendservice is hosted.

from trino.dbapi import connect from trino.auth import BasicAuthentication from trino import constants

user_name = "sample user" api_key = "somekey"

conn = connect( source="constants.DEFAULT_SOURCE, host="192.168.68.82", port="7732", auth=BasicAuthentication(user_name, api_key), http_scheme="https", )

cur = conn.cursor() query = """SELECT * FROM catalog.database.table""" cur.execute(query) rows = cur.fetchall() print(rows)

Log output

ERROR: (builtins.NoneType) None [SQL: 'NoneType' object is not subscriptable] (Background on this error at: https://sqlalche.me/e/14/dbapi)

Operating System

macos

Trino Python client version

4.0.0

Trino Server version

442

Python version

Python 3.10.4

Are you willing to submit PR?

vinayakmalik95 commented 20 hours ago

@ebyhr @hovaesco @hashhar

Kindly allow to raise the PR for the same

hashhar commented 19 hours ago

Can you share full backtrace?

if key in dict: is idomatic python. The issue isn't that, the issue is response itself was probably None.

See example:

>>> dict_with_key = {"k": "v"}
>>> dict_without_key = {"a": "v"}
>>> empty_dict = {}
>>> none_dict = None
>>>
>>> def check(d):
...     if "k" in d:
...             print("Exists")
...     else:
...             print("Does not exist")
...
>>> check(dict_with_key)
Exists
>>> check(dict_without_key)
Does not exist
>>> check(empty_dict)
Does not exist
>>> check(none_dict)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in check
TypeError: argument of type 'NoneType' is not iterable
hashhar commented 19 hours ago

And this error doesn't match your error, so the cause is probably something else. Please share full backtrace so that we can identify the reason.

Your error was:

ERROR: (builtins.NoneType) None [SQL: 'NoneType' object is not subscriptable] (Background on this error at: https://sqlalche.me/e/14/dbapi)