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
[AIRFLOW-3528] handle socket exception with SFTPOperator #4325
Conversation
add try/exception to catch socket exceptions
Codecov Report
@@ Coverage Diff @@
## master #4325 +/- ##
======================================
Coverage 78.1% 78.1%
======================================
Files 201 201
Lines 16471 16471
======================================
Hits 12864 12864
Misses 3607 3607 Continue to review full report at Codecov.
|
@@ -122,7 +122,11 @@ def execute(self, context): | |||
self.ssh_hook.remote_host = self.remote_host | |||
|
|||
with self.ssh_hook.get_conn() as ssh_client: | |||
sftp_client = ssh_client.open_sftp() | |||
try: |
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.
Does it need to be a Custom (Airflow) Exception?
Why can't the original exception just be raised?
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.
Currently it raises AirflowException as it's being handled at this line:
https://github.com/apache/incubator-airflow/blob/c83a4e5b952baa8d390e94d27fd12df888d3113e/airflow/contrib/operators/sftp_operator.py#L158
The propose here is just not to show the "Error while transferring (file_msg)" as this is confusing and file_msg is None.
This fix I don't think will do what we want, as I think now this will end up ultimately logging this as a message:
(I took a guess at what might be in the OSError). Which means we probably need to add some tests, via mocking, that makes |
I'm not sure what you mean... Since Python 3.3 socket.error is deprecated. It raised OSError instead. This PR doesn't attempt to solve the problem regarding why the connection fails. It only fix the message in order to avoid confusion. This problem was reported on Slack. @XD-DENG said that he will try to investigate about why the connection fails. |
I guessed at what error it might report. The main thing is you have try-inside-try, so this won't do what you expect. Additionally the error that was reporting was So the except you added (capturing Tests :) |
Agree with @ashb on the exception type to catch. Based on the exception/log shared in the Slack thread, it's an |
OK. Got it. |
Okay, thanks for trying though! |
Jira
Description
add try/exception to catch socket exceptions