Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ingest): fix reporting for missing secure view lineage #12430

Merged
merged 6 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -491,15 +491,25 @@
try:
view_definitions = self.data_dictionary.get_secure_view_definitions()
return view_definitions[db_name][schema_name][table_name]
except KeyError:

Check warning on line 494 in metadata-ingestion/src/datahub/ingestion/source/snowflake/snowflake_schema_gen.py

View check run for this annotation

Codecov / codecov/patch

metadata-ingestion/src/datahub/ingestion/source/snowflake/snowflake_schema_gen.py#L494

Added line #L494 was not covered by tests
# Received secure view definitions but the view is not present in results
self.structured_reporter.info(

Check warning on line 496 in metadata-ingestion/src/datahub/ingestion/source/snowflake/snowflake_schema_gen.py

View check run for this annotation

Codecov / codecov/patch

metadata-ingestion/src/datahub/ingestion/source/snowflake/snowflake_schema_gen.py#L496

Added line #L496 was not covered by tests
title="Secure view definition not found",
message="Lineage will be missing for the view.",
context=f"{db_name}.{schema_name}.{table_name}",
)
return None

Check warning on line 501 in metadata-ingestion/src/datahub/ingestion/source/snowflake/snowflake_schema_gen.py

View check run for this annotation

Codecov / codecov/patch

metadata-ingestion/src/datahub/ingestion/source/snowflake/snowflake_schema_gen.py#L501

Added line #L501 was not covered by tests
except Exception as e:
if isinstance(e, SnowflakePermissionError):
error_msg = (
"Failed to get secure views definitions. Please check permissions."
)
else:
error_msg = "Failed to get secure views definitions"
action_msg = (

Check warning on line 503 in metadata-ingestion/src/datahub/ingestion/source/snowflake/snowflake_schema_gen.py

View check run for this annotation

Codecov / codecov/patch

metadata-ingestion/src/datahub/ingestion/source/snowflake/snowflake_schema_gen.py#L503

Added line #L503 was not covered by tests
"Please check permissions."
if isinstance(e, SnowflakePermissionError)
else ""
)

self.structured_reporter.warning(
error_msg,
title="Failed to get secure views definitions",
message=f"Lineage will be missing for the view. {action_msg}",
context=f"{db_name}.{schema_name}.{table_name}",
exc=e,
)
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,63 @@ def test_snowflake_missing_snowflake_operations_permission_causes_pipeline_failu
assert "usage-permission-error" in [
failure.message for failure in pipeline.source.get_report().failures
]


@freeze_time(FROZEN_TIME)
def test_snowflake_missing_snowflake_secure_view_definitions_raises_pipeline_info(
pytestconfig,
snowflake_pipeline_config,
):
with mock.patch("snowflake.connector.connect") as mock_connect:
sf_connection = mock.MagicMock()
sf_cursor = mock.MagicMock()
mock_connect.return_value = sf_connection
sf_connection.cursor.return_value = sf_cursor

# Empty secure view definitions
sf_cursor.execute.side_effect = query_permission_response_override(
default_query_results,
[snowflake_query.SnowflakeQuery.get_secure_view_definitions()],
[],
)
pipeline = Pipeline(snowflake_pipeline_config)
pipeline.run()

pipeline.raise_from_status(raise_warnings=True)
assert pipeline.source.get_report().infos.as_obj() == [
{
"title": "Secure view definition not found",
"message": "Lineage will be missing for the view.",
"context": ["TEST_DB.TEST_SCHEMA.VIEW_1"],
}
]


@freeze_time(FROZEN_TIME)
def test_snowflake_failed_secure_view_definitions_query_raises_pipeline_warning(
pytestconfig,
snowflake_pipeline_config,
):
with mock.patch("snowflake.connector.connect") as mock_connect:
sf_connection = mock.MagicMock()
sf_cursor = mock.MagicMock()
mock_connect.return_value = sf_connection
sf_connection.cursor.return_value = sf_cursor

# Error in getting secure view definitions
sf_cursor.execute.side_effect = query_permission_error_override(
default_query_results,
[snowflake_query.SnowflakeQuery.get_secure_view_definitions()],
"Database 'SNOWFLAKE' does not exist or not authorized.",
)
pipeline = Pipeline(snowflake_pipeline_config)
pipeline.run()
assert pipeline.source.get_report().warnings.as_obj() == [
{
"title": "Failed to get secure views definitions",
"message": "Lineage will be missing for the view. Please check permissions.",
"context": [
"TEST_DB.TEST_SCHEMA.VIEW_1 <class 'datahub.ingestion.source.snowflake.snowflake_connection.SnowflakePermissionError'>: Database 'SNOWFLAKE' does not exist or not authorized."
],
}
]
Loading