def has_changes()

in bigquery_etl/view/__init__.py [0:0]


    def has_changes(self, target_project=None, credentials=None):
        """Determine whether there are any changes that would be published."""
        if any(str(self.path).endswith(p) for p in self.skip_publish()):
            return False

        if target_project and self.project != ConfigLoader.get(
            "default", "project", fallback="moz-fx-data-shared-prod"
        ):
            # view would be skipped because --target-project is set
            return False

        if credentials:
            client = bigquery.Client(credentials=credentials)
        else:
            client = bigquery.Client()
        target_view_id = self.target_view_identifier(target_project)
        try:
            table = client.get_table(target_view_id)
        except NotFound:
            print(f"view {target_view_id} will change: does not exist in BigQuery")
            return True

        try:
            expected_view_query = CREATE_VIEW_PATTERN.sub(
                "", sqlparse.format(self.content, strip_comments=True), count=1
            ).strip(";" + string.whitespace)

            actual_view_query = sqlparse.format(
                table.view_query, strip_comments=True
            ).strip(";" + string.whitespace)
        except TypeError:
            print(
                f"ERROR: There has been an issue formatting: {target_view_id}",
                file=sys.stderr,
            )
            raise

        if expected_view_query != actual_view_query:
            print(f"view {target_view_id} will change: query does not match")
            return True

        # check metadata
        if self.metadata is not None:
            if self.metadata.description != table.description:
                print(f"view {target_view_id} will change: description does not match")
                return True
            if self.metadata.friendly_name != table.friendly_name:
                print(
                    f"view {target_view_id} will change: friendly_name does not match"
                )
                return True
            if self.labels != table.labels:
                print(f"view {target_view_id} will change: labels do not match")
                return True

        table_schema = Schema.from_bigquery_schema(table.schema)

        if self.schema is not None and not self.schema.equal(table_schema):
            print(f"view {target_view_id} will change: schema does not match")
            return True

        return False