Skip to content

Commit

Permalink
Reraise exception from strict dataset URI checks (#39719)
Browse files Browse the repository at this point in the history
(cherry picked from commit cc9308c)
  • Loading branch information
uranusjr authored and ephraimbuddy committed Jun 5, 2024
1 parent c49e220 commit 6dd44dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
15 changes: 7 additions & 8 deletions airflow/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
7 changes: 2 additions & 5 deletions tests/datasets/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,8 @@ def normalizer(uri):
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)
Expand Down

0 comments on commit 6dd44dd

Please sign in to comment.