-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Refactor Bigtable Delete Instance Operator to remove redundant try/excep… #60727
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| Closes: #60687 | ||
|
|
||
| This PR removes redundant `try/except` blocks in `BigtableDeleteInstanceOperator` in `airflow/providers/google/cloud/operators/bigtable.py`. | ||
|
|
||
| The underlying `BigtableHook.delete_instance` method already handles the case where the instance does not exist by logging a warning. Therefore, catching `NotFound` in the operator was unnecessary and duplicated logic. | ||
|
|
||
| I have also: | ||
| - Updated the unit tests in `providers/google/tests/unit/google/cloud/operators/test_bigtable.py` to remove tests that specifically enforced this redundant exception handling. | ||
| - Corrected the docstring in `airflow/providers/google/cloud/hooks/bigtable.py` which incorrectly stated that `delete_instance` raises `NotFound`. | ||
|
|
||
| Generated-by: Antigravity (Google DeepMind) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -331,17 +331,7 @@ def execute(self, context: Context) -> None: | |
| 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 | ||
| hook.delete_instance(project_id=self.project_id, instance_id=self.instance_id) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another case in the error handling
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If such exception occurs, it will occur even without exception case, but without showing the error log "An error occured. Exiting.". |
||
|
|
||
|
|
||
| class BigtableCreateTableOperator(GoogleCloudBaseOperator, BigtableValidationMixin): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a file generated by the AI tool, we may not need this file here as it is the description for the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is not needed and should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to the above