Skip to content

Commit

Permalink
Reraise exception from strict dataset URI checks (apache#39719)
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored and romsharon98 committed Jul 26, 2024
1 parent 99ec36b commit a0a703f
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 @@ -94,14 +94,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 a0a703f

Please sign in to comment.