ajinkya-xyz opened a new pull request, #25705: URL: https://github.com/apache/airflow/pull/25705
Background : Pull request # [24084](https://github.com/apache/airflow/pull/24084) added the ability to provide `fnamtch` file pattern to SFTP sensor. But sensor fails to locate the file when the file pattern is provided. Issue : Code fails to get modified time once file matching to the given pattern is found. [Line # 77](https://github.com/apache/airflow/blob/main/airflow/providers/sftp/sensors/sftp.py#L77) from sftp.py file fails with no such file error. `mod_time = self.hook.get_mod_time(actual_file_to_check)` Root cause: Code assumes that the `get_file_by_pattern` method returns a complete path for a file matching the given `fnamtch` expression. While we are only getting file name in return. `get_file_by_pattern` internally relies on [Paramiko SFTP clients listdir()](https://docs.paramiko.org/en/stable/api/sftp.html#paramiko.sftp_client.SFTPClient.listdir) method to retrieve files contained in given path folder. `listdir()` method only returns file names and not the complete file path. Related code, sftp.py file [line # 68.](https://github.com/apache/airflow/blob/main/airflow/providers/sftp/sensors/sftp.py#L68) `file_from_pattern = self.hook.get_file_by_pattern(self.path, self.file_pattern)` Fix : Prepending the path to `actual_file_to_check `variable fixes the issue. `actual_file_to_check = os.path.join(self.path, file_from_pattern)` Related : [24084](https://github.com/apache/airflow/pull/24084) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
