diff --git a/bigquery_etl/view/__init__.py b/bigquery_etl/view/__init__.py index 5d39ddb705e..174ff61e64a 100644 --- a/bigquery_etl/view/__init__.py +++ b/bigquery_etl/view/__init__.py @@ -254,6 +254,12 @@ def has_changes(self, target_project=None): expected_view_query = CREATE_VIEW_PATTERN.sub( "", sqlparse.format(self.content, strip_comments=True), count=1 ).strip(";" + string.whitespace) + + if table.view_query is None: + # Materialized views do not have view_query. + # Always assume they are unchanged since they can't be replaced anyway + return False + actual_view_query = sqlparse.format( table.view_query, strip_comments=True ).strip(";" + string.whitespace)