-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Remove redundant try/except blocks in BigtableDeleteInstanceOperator
#60712
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
Remove redundant try/except blocks in BigtableDeleteInstanceOperator
#60712
Conversation
|
Hi @shahar1 Can you review it once. If it's good from your side. |
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.
Overall LGTM, small comment.
Also, could you please apply the same fix to the try..except block of BigtableDeleteTableOperator? (same principle)
@VladaZakharova I'll be happy for your review here as well - allegedly both Delete operators should never reach the NotFound case as it is already handled in the hook (it's a 7 years old code, so maybe things have been a bit different in the past). Please ignore, apologies for the hussle.
providers/google/tests/unit/google/cloud/operators/test_bigtable.py
Outdated
Show resolved
Hide resolved
Yes Once it is approved I will raise another PR and modify the |
|
@shahar1 not only delete operator but execute method in every class is having try and except block. will remove all in One PR? or Individual PR is required for every class in |
For this PR - you could also insert the other class (there is only one). |
Okay Sure |
|
@shahar1 Apologies for Late Updates. Also in |
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.
Hey @KamranImaaz , I went over the PR more thoroughly and I think that I've accidentally misled you -
I had initially thought that we use try..except in both the operators and hooks (which is indeed not necessary), but as it seems - the hook actually calls the API straight forward, and then the operators use try..except to reach idempotency in action, which is already the desired behavior.
When you delete a table and the instance does not exist, it rightously raises a RuntimeError error - because the instance is assumed to exist so you would be able to delete the table (whether it exists or not). If you run the Delete table operator, and the instance does not exist - it means that this assumption is wrong (regardless of the idempotency of the table), and the user needs to be alerted about it as a failure of the operator.
I sincerely apologize for missing it - but unfortunately it seems that we won't get too much from this one.
I'm aware that it's important for you to get your 3rd PR merged soon - so please try to look for existing issues labeled as good first issue, and let me know.
providers/google/src/airflow/providers/google/cloud/hooks/bigtable.py
Outdated
Show resolved
Hide resolved
|
btw, there might be a case for the other operator (DeleteInstance) to remove handling of |
Yes @shahar1 That doubt I was having initially. That's why I did not pushed it in initial commit as I specifically raised it for |
This reverts commit d5ae75a.
|
I have reverted the changes for |
BigtableDeleteInstanceOperator
|
Hi @shahar1 All CI checks have passed. Can you please review it once |
shahar1
left a comment
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.
LGTM
CC: @VladaZakharova @MaksYermak
- For the
NotFoundcase the hook takes care of idempotency already - I don't see a reason to duplicate this logic in the operator as it never actually reaches there (YAGNI). - The second exception seems redundant.
I have reviewed it. Please note that there's no need to tag me in each comment - once I'm tagged as reviewer, I get notified for every change and comment in the PR. |
I Generally have the habit of tagging. But I'll follow your advice. I Apologize for the inconvinience caused. |
|
Hello @KamranImaaz thank you for your PR! In my opinion it is not the same as handling errors by the |
In the issue I mean that the exceptions raised at the Operator Level is already taken care in Hook Level(Checks the existence of instance or not i.e Correct me if Iam wrong. Removing |
+1 for that: instance = self._get_client(project_id=project_id).instance(instance_id)
if not instance.exists():
return None
return instanceHow can the first line produce a |
|
@KamranImaaz @shahar1 thank you for the explanation! |
|
@KamranImaaz great job! Looking forward for more PRs. |
|
Thanks @shahar1 I will raise different PR for other operators and link it to the same issue. And it was nice working with you. I learned a lot from you. Once again Apologize for any inconvenience caused to you. |
|
Thanks @MaksYermak for your review. |
Fix #60687
Have Checked the Code and Modified accordingly also checked when the instance is not available to delete it should not log an error(Idempotent).
Tested Working Fine from My Side