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

Use the PID to terminate the session #568

Merged
merged 9 commits into from
Oct 11, 2023
Merged

Use the PID to terminate the session #568

merged 9 commits into from
Oct 11, 2023

Conversation

dbeatty10
Copy link
Contributor

@dbeatty10 dbeatty10 commented Aug 7, 2023

resolves #553
docs N/A

Problem

When we switched from psycopg2 to redshift_connector in dbt-redshift 1.5.0, the return type of fetchone() changed from a tuple to an array. This caused the query to terminate the session (based on the PID) to not be executed correctly.

Solution

This solution does two things:

  1. Optimistically assumes there is at least one item returned from the PID query and returns that value
  2. Directly executes a query to terminate the session (rather than using self.add_query(sql) which raises an error for some reason)

One or both can be modified depending on feedback from the code reviewer.

Also

While troubleshooting the solution noticed that there's a stack trace that didn't happen in dbt-core 1.4.0: dbt-labs/dbt-core#8338

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • 👈 This PR does not include any tests, and obviously none existed previously! Maybe that's okay 🤷
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc)

@cla-bot cla-bot bot added the cla:yes label Aug 7, 2023
@dbeatty10 dbeatty10 marked this pull request as ready for review August 7, 2023 23:56
@dbeatty10 dbeatty10 requested a review from a team as a code owner August 7, 2023 23:56
@dbeatty10 dbeatty10 added the ready_for_review Externally contributed PR has functional approval, ready for code review from Core engineering label Aug 7, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 7, 2023

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the dbt-redshift contributing guide.

@jmleon1219
Copy link

Can we get this merged?

Copy link
Contributor

@mikealfare mikealfare left a comment

Choose a reason for hiding this comment

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

Most of the review is context. The one change I would recommend is adding the logging statement backend. It doesn't need to be verbatim what I put, but I imagine that could be useful for troubleshooting when things go awry.

dbt/adapters/redshift/connections.py Show resolved Hide resolved
dbt/adapters/redshift/connections.py Show resolved Hide resolved
dbt/adapters/redshift/connections.py Show resolved Hide resolved
@mikealfare mikealfare merged commit 5d4f3f5 into main Oct 11, 2023
26 checks passed
@mikealfare mikealfare deleted the dbeatty/fix-553 branch October 11, 2023 01:15
abbywh pushed a commit to abbywh/dbt-redshift that referenced this pull request Oct 16, 2023
* The first element of the result is the PID
* Debug-level logging of high-level message + SQL
* Using redshift_connector `cursor.fetchone()`  returns `(<something>,)`
* Use cursor to call `select pg_terminate_backend({pid})` directly rather than using the `SQLConnectionManager`

---------

Co-authored-by: Mike Alfare <[email protected]>
github-actions bot pushed a commit that referenced this pull request Nov 6, 2023
* The first element of the result is the PID
* Debug-level logging of high-level message + SQL
* Using redshift_connector `cursor.fetchone()`  returns `(<something>,)`
* Use cursor to call `select pg_terminate_backend({pid})` directly rather than using the `SQLConnectionManager`

---------

Co-authored-by: Mike Alfare <[email protected]>
(cherry picked from commit 5d4f3f5)
colin-rogers-dbt pushed a commit that referenced this pull request Nov 6, 2023
* The first element of the result is the PID
* Debug-level logging of high-level message + SQL
* Using redshift_connector `cursor.fetchone()`  returns `(<something>,)`
* Use cursor to call `select pg_terminate_backend({pid})` directly rather than using the `SQLConnectionManager`

---------

Co-authored-by: Mike Alfare <[email protected]>
(cherry picked from commit 5d4f3f5)

Co-authored-by: Doug Beatty <[email protected]>
colin-rogers-dbt added a commit that referenced this pull request May 8, 2024
* adding SSO support for redshift

Committer: Abby Whittier <[email protected]>

* ADAP-891: Support test results as views (#614)

* implement store-failures-as tests

* Use the PID to terminate the session (#568)

* The first element of the result is the PID
* Debug-level logging of high-level message + SQL
* Using redshift_connector `cursor.fetchone()`  returns `(<something>,)`
* Use cursor to call `select pg_terminate_backend({pid})` directly rather than using the `SQLConnectionManager`

---------

Co-authored-by: Mike Alfare <[email protected]>

* added error checking for new optional user field

* black formatting

* move connection fixtures into the functional scope

* add iam user creds to the test.env template

* add test for database connection method

* add iam user auth test

* add IAM User auth test and second user auth method

* changie

* maintain existing behavior when not providing profile

* add AWS IAM profile

* pull in new env vars

* fixed env vars refs for CI

* move all repo vars to secrets

* split out connect method by connection method and provided information

* condition to produce just kwargs, consolidate connect method

* update .format to f-strings

* incorporate feedback from pr#630

* update kwargs logic flow

* updates to make space for iam role

* revert type on user

* revert test case decorator

* revert test case decorator

* revert error message

* add integration tests

* make space for both iam user and iam role in testing

* add role arn

* naming

* try supplying region for CI

* add region to CI env

* we can only support role credentials by profile

* move iam user specific config out of iam and into iam user

* add type annotations

* move iam defaults out of iam user

* add required params to test profiles

* add required params to test profiles

* simplify test files

* add expected fields back in

* split out unit test files

* split out unit test files

* add unit tests for iam role auth method

* standardize names

* allow for the default profile

* add unit tests for iam role access

* changie

* changie

---------

Co-authored-by: Abby Whittier <[email protected]>
Co-authored-by: Doug Beatty <[email protected]>
Co-authored-by: colin-rogers-dbt <[email protected]>
Co-authored-by: Anders <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes ready_for_review Externally contributed PR has functional approval, ready for code review from Core engineering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ADAP-721] [Bug] [Regression] Canceled or failed run creates a Database Error
4 participants