ksql-python icon indicating copy to clipboard operation
ksql-python copied to clipboard

IndexError after inserting

Open agmo1993 opened this issue 4 years ago • 9 comments

i'm receiving the following error after inserting into a stream using

client.ksql("INSERT INTO riderLocations (profileId, latitude, longitude) VALUES ('4ab5cbad', 37.3952, -122.0813);")`

Traceback (most recent call last): File "", line 1, in File "/home/ubuntu/.local/lib/python3.6/site-packages/ksql/client.py", line 42, in ksql return self.sa.ksql(ksql_string, stream_properties=stream_properties) File "/home/ubuntu/.local/lib/python3.6/site-packages/ksql/api.py", line 64, in ksql self._raise_for_status(r, response) File "/home/ubuntu/.local/lib/python3.6/site-packages/ksql/api.py", line 54, in _raise_for_status if r_json[0]["@type"] == "currentStatus" and r_json[0]["commandStatus"]["status"] == "ERROR": IndexError: list index out of range

Although the insert is successful and I can view it on a select query, any ideas about what's causing it to throw an error?

agmo1993 avatar Aug 23 '20 07:08 agmo1993

@agmo1993 Thank you for reporting issue. I will check the API response.

bryanyang0528 avatar Aug 25 '20 04:08 bryanyang0528

Indeed, I see the same.

Seems like we get []

romainr avatar Oct 22 '20 06:10 romainr

Not sure if it is the best way to fix it but it avoids it

https://github.com/bryanyang0528/ksql-python/pull/88

romainr avatar Oct 22 '20 06:10 romainr

@romainr Thank you for fixing it. Good contribution!

bryanyang0528 avatar Jul 11 '21 00:07 bryanyang0528

@agmo1993 Please try if this fixes this issue. Thank you.

bryanyang0528 avatar Jul 11 '21 00:07 bryanyang0528

I had the same issue and this solved it. When do you think will this be released?

javiersvg avatar Jul 11 '21 14:07 javiersvg

While we are waiting, I make this local correction :wink: :

class KsqlApiCustom(KSQLAPI):
    def __init__(self, url, max_retries=3, check_version=True, **kwargs):
        super().__init__(url, max_retries=max_retries,
                         check_version=check_version, **kwargs)
        self.sa._raise_for_status = self._raise_for_status

    @staticmethod
    def _raise_for_status(r, response):
        r_json = json.loads(response)
        if r.getcode() != 200:
            # seems to be the new API behavior
            if r_json.get("@type") == "statement_error" or r_json.get("@type") == "generic_error":
                error_message = r_json["message"]
                error_code = r_json["error_code"]
                stackTrace = r_json["stack_trace"]
                raise KSQLError(error_message, error_code, stackTrace)
            else:
                raise KSQLError("Unknown Error: {}".format(r.content))
        else:
            # seems to be the old API behavior, so some errors have status 200, bug??
            if r_json and r_json[0]["@type"] == "currentStatus" and r_json[0]["commandStatus"]["status"] == "ERROR":
                error_message = r_json[0]["commandStatus"]["message"]
                error_code = None
                stackTrace = None
                raise KSQLError(error_message, error_code, stackTrace)
            return True

ozair-junior avatar Nov 11 '21 20:11 ozair-junior

should be seeing a new release relatively soon. @bryanyang0528 is hard at work on updating the project. thanks for your patience.

KenCox94 avatar Jul 23 '22 01:07 KenCox94

Thank you @ozair-junior !!!

rgbarry avatar Aug 02 '22 11:08 rgbarry