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

IndexError after inserting #80

Open
agmo1993 opened this issue Aug 23, 2020 · 9 comments
Open

IndexError after inserting #80

agmo1993 opened this issue Aug 23, 2020 · 9 comments
Assignees
Labels

Comments

@agmo1993
Copy link

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?

@bryanyang0528
Copy link
Owner

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

@romainr
Copy link
Contributor

romainr commented Oct 22, 2020

Indeed, I see the same.

Seems like we get []

romainr added a commit to romainr/ksql-python that referenced this issue Oct 22, 2020
@romainr
Copy link
Contributor

romainr commented Oct 22, 2020

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

#88

bryanyang0528 added a commit that referenced this issue Oct 22, 2020
Avoid IndexError after INSERT query (#80)
@bryanyang0528
Copy link
Owner

@romainr Thank you for fixing it. Good contribution!

@bryanyang0528
Copy link
Owner

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

@javiersvg
Copy link

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

@ozair-junior
Copy link

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

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

@KenCox94
Copy link
Collaborator

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

@rgbarry
Copy link

rgbarry commented Aug 2, 2022

Thank you @ozair-junior !!!

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

No branches or pull requests

7 participants