Skip to content

Commit

Permalink
[AIRFLOW-6192] Stop creating Hook from SFTPSensor.__init__ (#6748)
Browse files Browse the repository at this point in the history

(cherry picked from commit 993e105)
  • Loading branch information
kaxil committed Dec 17, 2019
1 parent a0d6fc2 commit 263fada
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion airflow/contrib/sensors/sftp_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ class SFTPSensor(BaseSensorOperator):
def __init__(self, path, sftp_conn_id='sftp_default', *args, **kwargs):
super(SFTPSensor, self).__init__(*args, **kwargs)
self.path = path
self.hook = SFTPHook(sftp_conn_id)
self.hook = None
self.sftp_conn_id = sftp_conn_id

def poke(self, context):
self.hook = SFTPHook(self.sftp_conn_id)
self.log.info('Poking for %s', self.path)
try:
self.hook.get_mod_time(self.path)
Expand Down
6 changes: 6 additions & 0 deletions tests/contrib/sensors/test_sftp_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ def test_sftp_failure(self, sftp_hook_mock):
sftp_sensor.poke(context)
sftp_hook_mock.return_value.get_mod_time.assert_called_with(
'/path/to/file/1970-01-01.txt')

def test_hook_not_created_during_init(self):
sftp_sensor = SFTPSensor(
task_id='unit_test',
path='/path/to/file/1970-01-01.txt')
self.assertIsNone(sftp_sensor.hook)

0 comments on commit 263fada

Please sign in to comment.