Skip to content

Conversation

@BenediktRamsauer
Copy link
Contributor

@BenediktRamsauer BenediktRamsauer commented Feb 10, 2023

This PR will solve the issue registered by @RishuGuru in #28121.
It also takes into account the request from @potiuk in #28123 to add/fix the unit tests.

In summary, the SFTP Sensor was not finding the files when the file_pattern argument was used.
This was due to an incorrect assumption that the SFTP Hook function get_file_by_pattern would return the full path, where actually it only returns the file name (corrected in e08a702b508e01c8437e4a45eaa726bb39e4f47f).

The unit test that was checking that also made this assumption (corrected in 018f316f96ed5f6361eea59987996454ced73bc7).

Also the unit test test_file_with_pattern_parameter_call seemed to become redundant, and I removed it (full explanation in faa5a73d5b353a3c2c83a90b5040966158b97979).

closes: #28121

@boring-cyborg
Copy link

boring-cyborg bot commented Feb 10, 2023

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@BenediktRamsauer
Copy link
Contributor Author

Sorry guys, I made a mistake trying to upgrade my branch to the latest changes in apache:main

I will also solve the unsuccessful tests

The output of SFTPHook.get_file_by_pattern is a file name and not the
full path to the file.
To my understanding, the goal of `test_file_with_pattern_parameter_call`
is to test whether we can call the function with the `file_pattern`
parameter.
Due to the previous changes, the `os.path.join` requires to set a value
for `sftp_hook_mock.return_value.get_file_by_pattern.return_value` so that the
`poke` function would run.

The case where we set this value is dealt with
`test_file_present_with_pattern` and
`test_file_not_present_with_pattern`.
`test_file_with_pattern_parameter_call` thus does not test anything
different or more specific than the two other tests.
@dimberman dimberman merged commit 8e24387 into apache:main Feb 13, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Feb 13, 2023

Awesome work, congrats on your first merged pull request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SFTP Sensor fails to locate file

3 participants