This is an automated email from the ASF dual-hosted git repository. ephraimanierobi pushed a commit to branch v2-9-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 6db05894d7a3634404ccbba40f530361d4179316 Author: Tzu-ping Chung <[email protected]> AuthorDate: Mon May 20 23:55:56 2024 +0800 Reraise exception from strict dataset URI checks (#39719) (cherry picked from commit cc9308c71005e7fb69080b346923bf212cd87490) --- airflow/datasets/__init__.py | 15 +++++++-------- tests/datasets/test_dataset.py | 7 ++----- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/airflow/datasets/__init__.py b/airflow/datasets/__init__.py index 49ff5885cc..1c8548f32b 100644 --- a/airflow/datasets/__init__.py +++ b/airflow/datasets/__init__.py @@ -85,14 +85,13 @@ def _sanitize_uri(uri: str) -> str: parsed = normalizer(parsed) except ValueError as exception: if conf.getboolean("core", "strict_dataset_uri_validation", fallback=False): - raise exception - else: - warnings.warn( - f"The dataset URI {uri} is not AIP-60 compliant. " - f"In Airflow 3, this will raise an exception. More information: {repr(exception)}", - UserWarning, - stacklevel=3, - ) + raise + warnings.warn( + f"The dataset URI {uri} is not AIP-60 compliant: {exception}. " + f"In Airflow 3, this will raise an exception.", + UserWarning, + stacklevel=3, + ) return urllib.parse.urlunsplit(parsed) diff --git a/tests/datasets/test_dataset.py b/tests/datasets/test_dataset.py index 2b299e2293..29852febdc 100644 --- a/tests/datasets/test_dataset.py +++ b/tests/datasets/test_dataset.py @@ -457,11 +457,8 @@ def mock_get_uri_normalizer(normalized_scheme): def test__sanitize_uri_raises_warning(mock_warn): _sanitize_uri("postgres://localhost:5432/database.schema.table") msg = mock_warn.call_args.args[0] - assert "The dataset URI postgres://localhost:5432/database.schema.table is not AIP-60 compliant." in msg - assert ( - "In Airflow 3, this will raise an exception. More information: ValueError('Incorrect URI format')" - in msg - ) + assert "The dataset URI postgres://localhost:5432/database.schema.table is not AIP-60 compliant" in msg + assert "In Airflow 3, this will raise an exception." in msg @patch("airflow.datasets._get_uri_normalizer", mock_get_uri_normalizer)
