Fix : SFTP Sensor fails to locate file when file_pattern is provided #25705
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background : Pull request # 24084 added the ability to provide
fnamtchfile 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 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_patternmethod returns a complete path for a file matching the givenfnamtchexpression. While we are only getting file name in return.get_file_by_patterninternally relies on Paramiko SFTP clients 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.
file_from_pattern = self.hook.get_file_by_pattern(self.path, self.file_pattern)Fix : Prepending the path to
actual_file_to_checkvariable fixes the issue.actual_file_to_check = os.path.join(self.path, file_from_pattern)Related : 24084