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

"THROW_ERROR" function does not throw error in vertica_python using python3 #272

Closed
alecsaunders opened this issue Mar 25, 2019 · 1 comment
Labels
bug protocol requires Vertica protocol knowledge

Comments

@alecsaunders
Copy link

The Vertica Error-Handling Function THROW_ERROR does not in fact throw an error on execution when using vertica_python using python3.

Python Version: 3.7.2
Vertica-python version: 0.9.1

When I execute the sql containing the THROW_ERROR function python does NOT throw an error.

cur.execute("SELECT THROW_ERROR('test error')")

It is only when fetchall() or fetchone() is called that an error is thrown.

I have tested this issue by simply calling the function (as shown above) and when using the function inside a case statement:

cur.execute("SELECT CASE WHEN COUNT(*) = 10 THEN 'SUCSESS!' ELSE THROW_ERROR('error') END FROM test;

The logic of my script does not require me to return any results with fetchall(). I would like THROW_ERROR to just throw an error on execution.


To provide some help in diagnosing this issue, I noticed that when _execute_simple_query is called in cursor.py, the instance type of self._message (row 479) is RowDescription and not ErrorResponse as it should be. I did some debugging and here is the self._message.

RowDescription: [{'name': 'THROW_ERROR', 'table_oid': 0, 'schema_name': None, 'table_name': None, 'attribute_number': 0, 'data_type_oid': 9, 'data_type_size': 65535, 'data_type_name': 'Varchar', 'null_ok': True, 'is_identity': False, 'type_modifier': 15, 'format_code': 0}]
@sitingren
Copy link
Member

@alecsaunders Thanks for reporting. This is a similar issue of #255. Please read the explanation in #255.

Here are protocol messages that are sending(=>) and receiving(<=) during sql executions:

=> Query: SELECT THROW_ERROR('test error');
<= RowDescription: cursor.execute() returned at here
<= ErrorResponse

In vertica-python version 0.9.1, the logic of cursor.execute() makes the function stop reading remaining protocol messages if it receives a RowDescription message. For your specific problem, we can add error handling after receiving RowDescription messages. But in general, ErrorResponse messages can occur anytime in the protocol cycle of a query, only running cursor.fetchall() can you iterate through all remaining protocol messages and catch ErrorResponse.

@sitingren sitingren added enhancement protocol requires Vertica protocol knowledge labels Mar 26, 2019
sitingren added a commit to sitingren/vertica-python that referenced this issue Apr 9, 2019
@sitingren sitingren added bug and removed enhancement labels Apr 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug protocol requires Vertica protocol knowledge
Projects
None yet
Development

No branches or pull requests

2 participants