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

Custom fetch all handler for vertica to not miss errors #34041

Merged
merged 11 commits into from
Sep 6, 2023

Conversation

darkag
Copy link
Contributor

@darkag darkag commented Sep 2, 2023

Change the default fetch all handler for vertica provider in order to catch all errors in multi-statement query (issue 32993)
Closes: #32993


def vertica_fetch_all_handler(cursor) -> list[tuple] | None:
"""Replace the default DbApiHook fetch_all_handler ."""
to_return = fetch_all_handler(cursor)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we rename to_return? Does rows make sense as the name of this value? or result might be a bit better than to_return

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I'll rename it as result

Comment on lines 31 to 37
if cursor.description is not None:
while cursor.nextset():
if cursor.description is not None:
row = cursor.fetchone()
while row:
row = cursor.fetchone()
return to_return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this value be changed during the execution of lines 31-36? It seems this variable is not touched after it is assigned. But I guess this is something related to cursor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returned value will not change between line 31 to 37, all this code is here to make vertica client throws error.
If you run the following sql:
INSERT INTO MyTable (Key, Label) values (1, 'test 1');
INSERT INTO MyTable (Key, Label) values (1, 'test 2');
INSERT INTO MyTable (Key, Label) values (3, 'test 3');

each insert has its own result set and if you don't try to fetch data of thoses result sets you won't detect error on the second insert.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nasty behaviour of Vertica

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, fortunately that as beginning with airflow I tested that it worked as I thincked, but if I had the habit with other database before I may have ended with a really bad surprise.

@potiuk
Copy link
Member

potiuk commented Sep 4, 2023

Interesting ... LGTM.

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One change request though: : could you please add some comments (docstring) in VerticaHook explaining why we have this and explaining why we have this complexity in the Vertica Hook. It should contain link to the issue that you have in the commit message as well as some explanation for those who would like to use their own handler for Vertica Hook.

I think without it it will be difficult for future maintainers to figure out why we are doing it and for the users to properly write their own handlers if they choose to do so.

@darkag
Copy link
Contributor Author

darkag commented Sep 5, 2023

Added docstring (hope this is understandable enough)

@potiuk
Copy link
Member

potiuk commented Sep 6, 2023

Thanks! LGTM!

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

Successfully merging this pull request may close these issues.

Error not detected in multi-statement vertica query
3 participants