Repository: dbt-labs/dbt-redshift
Pull request #433 (2023-05-08 16:34:17)

Default connect_timeout to None
resolves https://github.com/dbt-labs/dbt-redshift/issues/427
<!---
  Include the number of the issue addressed by this PR above if applicable.
  PRs for code changes without an associated issue *will not be merged*.
  See CONTRIBUTING.md for more information.

  Example:
    resolves #1234
-->

### Description

<!---
  Describe the Pull Request here. Add any references and info to help reviewers
  understand your changes. Include any tradeoffs you considered.
-->
Change the default of connect_timeout to None. If connect_timeout is not provided in profiles.yml, connect_timeout will be defaulted to None. User can also configure connect_timeout in profiles.yml to the duration of seconds before connection times out.

### Checklist

- [x] I have read [the contributing guide](https://github.com/dbt-labs/dbt-redshift/blob/main/CONTRIBUTING.md) and understand what's expected of me
- [x] I have signed the [CLA](https://docs.getdbt.com/docs/contributor-license-agreements)
- [ ] I have run this code in development and it appears to resolve the stated issue
- [ ] This PR includes tests, or tests are not required/relevant for this PR
- [ ] I have [opened an issue to add/update docs](https://github.com/dbt-labs/docs.getdbt.com/issues/new/choose), or docs changes are not required/relevant for this PR
- [x] I have run `changie new` to [create a changelog entry](https://github.com/dbt-labs/dbt-redshift/blob/main/CONTRIBUTING.md#Adding-CHANGELOG-Entry)



Patch:
diff --git a/.changes/unreleased/Fixes-20230508-094834.yaml b/.changes/unreleased/Fixes-20230508-094834.yaml
new file mode 100644
index 00000000..378c428e
--- /dev/null
+++ b/.changes/unreleased/Fixes-20230508-094834.yaml
@@ -0,0 +1,6 @@
+kind: Fixes
+body: Fix redshift_connector issue of timing out after 30s
+time: 2023-05-08T09:48:34.019843-07:00
+custom:
+  Author: jiezhen-chen
+  Issue: "427"
diff --git a/dbt/adapters/redshift/connections.py b/dbt/adapters/redshift/connections.py
index 5cea2c73..1a1e7353 100644
--- a/dbt/adapters/redshift/connections.py
+++ b/dbt/adapters/redshift/connections.py
@@ -72,7 +72,7 @@ class RedshiftCredentials(Credentials):
     autocreate: bool = False
     db_groups: List[str] = field(default_factory=list)
     ra3_node: Optional[bool] = False
-    connect_timeout: int = 30
+    connect_timeout: Optional[int] = None
     role: Optional[str] = None
     sslmode: Optional[str] = None
     retries: int = 1


Test patch:
diff --git a/tests/unit/test_redshift_adapter.py b/tests/unit/test_redshift_adapter.py
index c90a53df..9a43c1ce 100644
--- a/tests/unit/test_redshift_adapter.py
+++ b/tests/unit/test_redshift_adapter.py
@@ -72,7 +72,7 @@ class TestRedshiftAdapter(unittest.TestCase):
             port=5439,
             auto_create=False,
             db_groups=[],
-            timeout=30,
+            timeout=None,
             region="us-east-1",
         )
 
@@ -91,7 +91,7 @@ class TestRedshiftAdapter(unittest.TestCase):
             auto_create=False,
             db_groups=[],
             region="us-east-1",
-            timeout=30,
+            timeout=None,
         )
 
     @mock.patch("redshift_connector.connect", Mock())
@@ -115,10 +115,27 @@ class TestRedshiftAdapter(unittest.TestCase):
             auto_create=False,
             db_groups=[],
             profile=None,
-            timeout=30,
+            timeout=None,
             port=5439,
         )
 
+    @mock.patch("redshift_connector.connect", Mock())
+    def test_conn_timeout_30(self):
+        self.config.credentials = self.config.credentials.replace(connect_timeout=30)
+        connection = self.adapter.acquire_connection("dummy")
+        connection.handle
+        redshift_connector.connect.assert_called_once_with(
+            host="thishostshouldnotexist.test.us-east-1",
+            database="redshift",
+            user="root",
+            password="password",
+            port=5439,
+            auto_create=False,
+            db_groups=[],
+            region="us-east-1",
+            timeout=30,
+        )
+
     @mock.patch("redshift_connector.connect", Mock())
     @mock.patch("boto3.Session", Mock())
     def test_explicit_iam_conn_with_profile(self):
@@ -143,7 +160,7 @@ class TestRedshiftAdapter(unittest.TestCase):
             password="",
             user="",
             profile="test",
-            timeout=30,
+            timeout=None,
             port=5439,
         )
 
@@ -169,7 +186,7 @@ class TestRedshiftAdapter(unittest.TestCase):
             password="",
             user="",
             profile="test",
-            timeout=30,
+            timeout=None,
             port=5439,
         )
 
@@ -197,7 +214,7 @@ class TestRedshiftAdapter(unittest.TestCase):
             password="",
             user="",
             profile="test",
-            timeout=30,
+            timeout=None,
             port=5439,
         )
 
@@ -226,7 +243,7 @@ class TestRedshiftAdapter(unittest.TestCase):
                 password="",
                 user="",
                 profile="test",
-                timeout=30,
+                timeout=None,
                 port=5439,
             )
 
@@ -255,7 +272,7 @@ class TestRedshiftAdapter(unittest.TestCase):
                 password="",
                 user="",
                 profile="test",
-                timeout=30,
+                timeout=None,
                 port=5439,
             )
 
@@ -283,7 +300,7 @@ class TestRedshiftAdapter(unittest.TestCase):
                 user="",
                 profile="test",
                 port=5439,
-                timeout=30,
+                timeout=None,
             )
         self.assertTrue("'host' must be provided" in context.exception.msg)