-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Description
Apache Airflow Provider(s)
Versions of Apache Airflow Providers
No response
Apache Airflow version
3.2.0
Operating System
Windows(Local Development)
Deployment
Official Apache Airflow Helm Chart
Deployment details
No response
What happened
In The Operator Bigtable.py contains several try/except block that are not required and not expected in Operator Level as it Should be handled at Hook Level.
Moreover The Exceptions raised at the Operator level are already Handled at the Hook Level. So what's the point of duplicating it in Operator Level. Let me take an example here
Bigtable.py operator file contains one class BigtableDeleteInstanceOperator which has a method
` def execute(self, context: Context) -> None:
hook = BigtableHook(
gcp_conn_id=self.gcp_conn_id,
impersonation_chain=self.impersonation_chain,
)
try:
hook.delete_instance(project_id=self.project_id, instance_id=self.instance_id)
except google.api_core.exceptions.NotFound:
self.log.info(
"The instance '%s' does not exist in project '%s'. Consider it as deleted",
self.instance_id,
self.project_id,
)
except google.api_core.exceptions.GoogleAPICallError as e:
self.log.error("An error occurred. Exiting.")
raise e`
It raises exception when the instance does not exists which is already handled at the Hook level see below
` @GoogleBaseHook.fallback_to_default_project_id
def delete_instance(self, instance_id: str, project_id: str) -> None:
instance = self.get_instance(instance_id=instance_id, project_id=project_id)
if instance:
instance.delete()
else:
self.log.warning(
"The instance '%s' does not exist in project '%s'. Exiting", instance_id, project_id
)`
Like wise the whole Bigquery.py has lot's of not necessary try/except blocks.
What you think should happen instead
No response
How to reproduce
I will raise a PR for the above mentioned code first and in the next PR I will fix the whole Bigtable.py file.
Anything else
No response
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct