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 e80a6bc70cc Use built-in exceptions for Postgres hook input validation 
(#70537)
e80a6bc70cc is described below

commit e80a6bc70cc4144d6242b4c975372b1694265b88
Author: Dr Alex Mitre <[email protected]>
AuthorDate: Fri Jul 31 12:57:07 2026 -0600

    Use built-in exceptions for Postgres hook input validation (#70537)
---
 generated/known_airflow_exceptions.txt                             | 1 -
 .../postgres/src/airflow/providers/postgres/hooks/postgres.py      | 7 ++-----
 providers/postgres/tests/unit/postgres/hooks/test_postgres.py      | 4 ++--
 3 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/generated/known_airflow_exceptions.txt 
b/generated/known_airflow_exceptions.txt
index 5a96a60860b..fcab3746d5c 100644
--- a/generated/known_airflow_exceptions.txt
+++ b/generated/known_airflow_exceptions.txt
@@ -375,7 +375,6 @@ 
providers/opensearch/src/airflow/providers/opensearch/log/os_task_handler.py::1
 
providers/opensearch/src/airflow/providers/opensearch/operators/opensearch.py::9
 providers/pagerduty/src/airflow/providers/pagerduty/hooks/pagerduty.py::1
 
providers/pagerduty/src/airflow/providers/pagerduty/hooks/pagerduty_events.py::2
-providers/postgres/src/airflow/providers/postgres/hooks/postgres.py::2
 providers/presto/src/airflow/providers/presto/hooks/presto.py::1
 providers/samba/src/airflow/providers/samba/transfers/gcs_to_samba.py::1
 providers/segment/src/airflow/providers/segment/hooks/segment.py::2
diff --git 
a/providers/postgres/src/airflow/providers/postgres/hooks/postgres.py 
b/providers/postgres/src/airflow/providers/postgres/hooks/postgres.py
index 3821779e261..afbb2094639 100644
--- a/providers/postgres/src/airflow/providers/postgres/hooks/postgres.py
+++ b/providers/postgres/src/airflow/providers/postgres/hooks/postgres.py
@@ -26,7 +26,6 @@ from typing import TYPE_CHECKING, Any, Literal, NoReturn, 
Protocol, TypeAlias, c
 from more_itertools import chunked
 
 from airflow.providers.common.compat.sdk import (
-    AirflowException,
     AirflowOptionalProviderFeatureException,
     Connection,
     conf,
@@ -189,7 +188,7 @@ class PostgresHook(DbApiHook):
         conn = self.connection
         query = conn.extra_dejson.get("sqlalchemy_query", {})
         if not isinstance(query, dict):
-            raise AirflowException("The parameter 'sqlalchemy_query' must be 
of type dict!")
+            raise TypeError("The parameter 'sqlalchemy_query' must be of type 
dict!")
         if conn.extra_dejson.get("iam", False):
             conn.login, conn.password, conn.port = self.get_iam_token(conn)
         return URL.create(
@@ -222,9 +221,7 @@ class PostgresHook(DbApiHook):
             if _cursor == "namedtuplecursor":
                 return namedtuple_row
             if _cursor == "realdictcursor":
-                raise AirflowException(
-                    "realdictcursor is not supported with psycopg3. Use 
dictcursor instead."
-                )
+                raise ValueError("realdictcursor is not supported with 
psycopg3. Use dictcursor instead.")
             valid_cursors = "dictcursor, namedtuplecursor"
             raise ValueError(f"Invalid cursor passed {_cursor}. Valid options 
are: {valid_cursors}")
 
diff --git a/providers/postgres/tests/unit/postgres/hooks/test_postgres.py 
b/providers/postgres/tests/unit/postgres/hooks/test_postgres.py
index a9eff1bcb6f..12fe869a212 100644
--- a/providers/postgres/tests/unit/postgres/hooks/test_postgres.py
+++ b/providers/postgres/tests/unit/postgres/hooks/test_postgres.py
@@ -27,7 +27,7 @@ import pytest
 import sqlalchemy
 
 from airflow.models import Connection
-from airflow.providers.common.compat.sdk import AirflowException, 
AirflowOptionalProviderFeatureException
+from airflow.providers.common.compat.sdk import 
AirflowOptionalProviderFeatureException
 from airflow.providers.postgres.dialects.postgres import PostgresDialect
 from airflow.providers.postgres.hooks.postgres import PostgresHook
 
@@ -110,7 +110,7 @@ class TestPostgresHookConn:
         )
         hook = PostgresHook(connection=conn)
 
-        with pytest.raises(AirflowException):
+        with pytest.raises(TypeError, match="'sqlalchemy_query' must be of 
type dict"):
             hook.sqlalchemy_url
 
     @pytest.mark.parametrize("aws_conn_id", [NOTSET, None, "mock_aws_conn"])

Reply via email to