Skip to content
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

Optionally raise an error if source file does not exist in GCSToGCSOperator #21391

Merged
merged 5 commits into from
Feb 10, 2022

Conversation

davidpr91
Copy link
Contributor

@davidpr91 davidpr91 commented Feb 7, 2022

Right now when using GCSToGCSOperator to copy a file from one bucket to another, if the source file does not exist, nothing happens and the task is considered successful. This could be good for some use cases, for example, when you want to copy all the files from a directory or that match a specific pattern.
But for some other cases, like when you only want to copy one specific blob, it might be useful to raise an exception if the source file can't be found. Otherwise, the task would be failing silently.

This PR adds the flag "source_object_required" to GCSToGCSOperator to enable this feature. By default, for backward compatibility, the value set to False. If we pass set the flag as True, then, if the source_objects are blobs (not folders or patterns) and they don't exist, the task will fail.

closes: #21388


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.

@boring-cyborg boring-cyborg bot added area:providers provider:google Google (including GCP) related issues labels Feb 7, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Feb 7, 2022

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 (flake8, 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

@potiuk
Copy link
Member

potiuk commented Feb 7, 2022

Could you please add a unit test for it ? You can use the existing tests as a base.

msg = (
f'{prefix} does not exist in bucket {self.source_bucket}'
)
self.log.warning(msg)
Copy link
Contributor

@raphaelauv raphaelauv Feb 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move the log inside the if, so current users do not see logs with WARNING level

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right! I've just modified it

@davidpr91
Copy link
Contributor Author

@potiuk I've added a unit test

@github-actions github-actions bot added the okay to merge It's ok to merge this PR as it does not require more tests label Feb 8, 2022
@github-actions
Copy link

github-actions bot commented Feb 8, 2022

The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest main or amend the last commit of the PR, and push it with --force-with-lease.

@potiuk
Copy link
Member

potiuk commented Feb 8, 2022

Any chance to fix the static check @davidpr91 (shortly as I am preparing RC2 release tonight)?

Comment on lines 93 to 95
:param source_object_required: When source_object_required is True, if you want to copy / move a specific blob
and it doesn't exist, an exception is raised and the task is marked as failed.
This parameter doesn't have any effect when the source_object that you pass is a folder or pattern.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we simplify it? When ___ is true, if .... is a sentence that is hard to follow.
You need to fix the sentence any way as it fails the static checks (line to long) so please try to simplify it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've simplified the description. Thanks for the feedback!

@davidpr91
Copy link
Contributor Author

@potiuk static checks should be fixed now

@davidpr91
Copy link
Contributor Author

Hello. I see there is a failing check, but I'm not sure how this is related to my change. Could you help me? Thank you!

@potiuk
Copy link
Member

potiuk commented Feb 10, 2022

Hello. I see there is a failing check, but I'm not sure how this is related to my change. Could you help me? Thank you!

Just rebase. There is this new feature of GitHub that you can try:

image

@davidpr91
Copy link
Contributor Author

@potiuk It worked. Thank you!

@potiuk
Copy link
Member

potiuk commented Feb 10, 2022

Not entirely it seems:). Let me close/reopen to rebuild. I think we need to add a trrigger for another even in our CI :)

@potiuk potiuk closed this Feb 10, 2022
@potiuk potiuk reopened this Feb 10, 2022
@potiuk
Copy link
Member

potiuk commented Feb 10, 2022

It worked indeed :)

@potiuk potiuk merged commit 51aff27 into apache:main Feb 10, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Feb 10, 2022

Awesome work, congrats on your first merged pull request!

ferruzzi pushed a commit to ferruzzi/airflow that referenced this pull request Feb 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers okay to merge It's ok to merge this PR as it does not require more tests provider:google Google (including GCP) related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optionally raise an error if source file does not exist in GCSToGCSOperator
4 participants