From 4f02b910ce4181fd3f656f4bb4355fcfdb414b40 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Tue, 8 Aug 2023 22:46:16 +0800 Subject: [PATCH 1/2] fix(providers.google): add setter to BigQueryInsertJobOperator sql property due to the introduction of this property, users who set the sql attribute to some value will encounter an AttributeError This commit indents to mitigate this issue --- airflow/providers/google/cloud/operators/bigquery.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/airflow/providers/google/cloud/operators/bigquery.py b/airflow/providers/google/cloud/operators/bigquery.py index d6654141532a..5172d72730cd 100644 --- a/airflow/providers/google/cloud/operators/bigquery.py +++ b/airflow/providers/google/cloud/operators/bigquery.py @@ -2739,11 +2739,19 @@ def __init__( @property def sql(self) -> str | None: + _sql = getattr(self, "_sql", None) + if _sql: + return _sql + try: return self.configuration["query"]["query"] except KeyError: return None + @sql.setter + def sql(self, sql_value: str): + self._sql = sql_value + def prepare_template(self) -> None: # If .json is passed then we have to read the file if isinstance(self.configuration, str) and self.configuration.endswith(".json"): From cbdb3f3c0a665c7c6d21926d1b3451e99a468066 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Tue, 8 Aug 2023 23:01:54 +0800 Subject: [PATCH 2/2] fix(providers.google): add deprecationg warning to BigQueryInsertJobOperator sql.setter --- airflow/providers/google/cloud/operators/bigquery.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/airflow/providers/google/cloud/operators/bigquery.py b/airflow/providers/google/cloud/operators/bigquery.py index 5172d72730cd..99a15e66d075 100644 --- a/airflow/providers/google/cloud/operators/bigquery.py +++ b/airflow/providers/google/cloud/operators/bigquery.py @@ -2750,6 +2750,15 @@ def sql(self) -> str | None: @sql.setter def sql(self, sql_value: str): + warnings.warn( + ( + "Assigning value to sql is deprecated. " + "This setter will be removed in the next major release and" + " will raise an AttributeError when assigning value to sql" + ), + AirflowProviderDeprecationWarning, + stacklevel=2, + ) self._sql = sql_value def prepare_template(self) -> None: