This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 9837ceef398 Added validation for missing redshift connection host in 
postgres hook openlineage (#60918)
9837ceef398 is described below

commit 9837ceef39856f4e8502e2ba0de4b65fbc4d144f
Author: Justin Pakzad <[email protected]>
AuthorDate: Sat Feb 14 19:47:24 2026 -0500

    Added validation for missing redshift connection host in postgres hook 
openlineage (#60918)
---
 .../src/airflow/providers/postgres/hooks/postgres.py |  7 ++++++-
 .../tests/unit/postgres/hooks/test_postgres.py       | 20 ++++++++++++++------
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git 
a/providers/postgres/src/airflow/providers/postgres/hooks/postgres.py 
b/providers/postgres/src/airflow/providers/postgres/hooks/postgres.py
index f8f22578923..52a0d40a772 100644
--- a/providers/postgres/src/airflow/providers/postgres/hooks/postgres.py
+++ b/providers/postgres/src/airflow/providers/postgres/hooks/postgres.py
@@ -580,7 +580,12 @@ class PostgresHook(DbApiHook):
         aws_conn_id = connection.extra_dejson.get("aws_conn_id", "aws_default")
 
         port = connection.port or 5439
-        cluster_identifier = connection.extra_dejson.get("cluster-identifier", 
connection.host.split(".")[0])
+        cluster_identifier = connection.extra_dejson.get("cluster-identifier")
+        if cluster_identifier is None and not connection.host:
+            raise ValueError(
+                "connection host is required for Redshift OpenLineage when 
cluster-identifier is not set in extras."
+            )
+        cluster_identifier = cluster_identifier or 
connection.host.split(".")[0]
         region_name = AwsBaseHook(aws_conn_id=aws_conn_id).region_name
 
         return f"{cluster_identifier}.{region_name}:{port}"
diff --git a/providers/postgres/tests/unit/postgres/hooks/test_postgres.py 
b/providers/postgres/tests/unit/postgres/hooks/test_postgres.py
index a1c8d757bcb..788e26095d8 100644
--- a/providers/postgres/tests/unit/postgres/hooks/test_postgres.py
+++ b/providers/postgres/tests/unit/postgres/hooks/test_postgres.py
@@ -126,18 +126,22 @@ class TestPostgresHookConn:
     @pytest.mark.parametrize("aws_conn_id", [NOTSET, None, "mock_aws_conn"])
     @pytest.mark.parametrize("port", [5432, 5439, None])
     @pytest.mark.parametrize(
-        ("host", "conn_cluster_identifier", "expected_host"),
+        ("host", "conn_cluster_identifier", "expected_host", 
"raises_exception"),
         [
             (
                 
"cluster-identifier.ccdfre4hpd39h.us-east-1.redshift.amazonaws.com",
                 NOTSET,
                 "cluster-identifier.us-east-1",
+                False,
             ),
             (
                 
"cluster-identifier.ccdfre4hpd39h.us-east-1.redshift.amazonaws.com",
                 "different-identifier",
                 "different-identifier.us-east-1",
+                False,
             ),
+            (None, NOTSET, None, True),
+            (None, "cluster-identifier", "cluster-identifier.us-east-1", 
False),
         ],
     )
     def test_openlineage_methods_with_redshift(
@@ -148,6 +152,7 @@ class TestPostgresHookConn:
         host,
         conn_cluster_identifier,
         expected_host,
+        raises_exception,
     ):
         mock_aws_hook_class = 
mocker.patch("airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHook")
 
@@ -167,11 +172,14 @@ class TestPostgresHookConn:
         # Mock AWS Connection
         mock_aws_hook_instance = mock_aws_hook_class.return_value
         mock_aws_hook_instance.region_name = "us-east-1"
-
-        assert (
-            
self.db_hook._get_openlineage_redshift_authority_part(self.connection)
-            == f"{expected_host}:{port or 5439}"
-        )
+        if raises_exception:
+            with pytest.raises(ValueError, match="connection host is 
required"):
+                
self.db_hook._get_openlineage_redshift_authority_part(self.connection)
+        else:
+            assert (
+                
self.db_hook._get_openlineage_redshift_authority_part(self.connection)
+                == f"{expected_host}:{port or 5439}"
+            )
 
     def test_get_conn_non_default_id(self, mock_connect):
         self.db_hook.test_conn_id = "non_default"

Reply via email to