-
Notifications
You must be signed in to change notification settings - Fork 103
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
catch error in multi-query batches #140
Conversation
@jtcohen6, I'm struggling with how to fetch then handle the pyodbc's current approach to fixingI've implemented @jeroen-mostert's approach. I'm not exactly sure what this PR now surfaces an "unhandled" error, but doesn't return the desired (and previous state)this is what the output should look like using a version of dbt-sqlserver before the adapter macros had query batches. alternative solution split the queries and add/execute them independently?One approach would be to implement something like
|
If it helps (actually I'm pretty sure it doesn't but I'm putting it out here anyway :-)) there's something weird with how pyodbc treats multi-statement batches for SQL Server. Calling All this is not to suggest this is something that could or should be changed in the pyodbc layer just to make dbt happy, of course, since that might be quite impactful; executing individual statements is still the safest way to go. A Parsing batches and splitting them manually on anything but a dedicated batch separator like good old |
Awesome fix! 👍 Faced with this today in my work with snapshot functionality. |
@jeroen-mostert I really find myself agreeing. It's not good how pyodbc treats errors from multi-statement batches. It's also preferable, wherever possible, to supply individual queries one at a time, so long as they can be executed within a single transaction/session.
That comes from the Snowflake python connector here. The logic in this method is somewhere between "just split on semicolon" and "SQL parser with full fidelity." If I remember right, the Snowflake python connector does not properly handle multiple query statements at once (semicolon-delimited), so this is what we have to use instead. |
Thank you for pushing this up! Sorry I didn't give better instructions for how to reproduce the error :D So far (even with the cursor2 oddity) runs with this new setup, and I'm seeing failures where I would expect now. And I'm catching errors I was missing :O (installed on a new venv with |
Using this right now in my environment. So far so good, I've caught 20 plus errors I was missing :O |
…lserver into cursor_conundrum
@jeroen-mostert, you are my hero -- not only for the fix but the depth of knowledge you were able to share. You certainly make me feel a lot saner, now that I know that both That said, these EXEC statements are only needed to support the multi-database scenario that is only possible with on-premise SQL Server. There's a part of me that wants to kick this behavior into it's own adapter ( For now, we should definitely merge and release this to everyone. @mikaelene would you do the honors of releasing a |
Fixes: #139, #135
#124 modified core adapter macros (e.g.
create_view_as()
) to be multi-query batches that were previously single queries.This PR attempts to use @jeroen-mostert's solution to iteration through each query in a query batch looking for errors