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

Example dag slackfile #17400

Merged
merged 25 commits into from
Aug 16, 2021
Merged

Example dag slackfile #17400

merged 25 commits into from
Aug 16, 2021

Conversation

subkanthi
Copy link
Contributor

closes: #17368

  • Fixed bug with SlackAPIFileOperator with uploading file.
  • Added example dag to demonstrate support for uploading file and file content.

…g_slackfile

� Conflicts:
�	airflow/providers/slack/operators/slack.py
@potiuk
Copy link
Member

potiuk commented Aug 4, 2021

some docs and test failures

@github-actions
Copy link

github-actions bot commented Aug 4, 2021

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.

@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 Aug 4, 2021
Comment on lines 190 to 197
log += (
"*** !!!! Please make sure that all your webservers and workers have"
" the same 'secret_key' configured in 'webserver' section !!!!!\n***"
)
log += (
"*** See more at https://airflow.apache.org/docs/apache-airflow/"
"stable/configurations-ref.html#secret-key\n***"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't related to this PR

Copy link
Member

Choose a reason for hiding this comment

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

I broke it and just fixed it in main (bad Jarek!)

Copy link
Member

Choose a reason for hiding this comment

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

Needs rebase

ui_color = '#44BEDF'

def __init__(
self,
channel: str = '#general',
initial_comment: str = 'No message has been set!',
filename: str = None,
file: str = None,
Copy link
Member

Choose a reason for hiding this comment

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

It looks like a breaking change. Is there any way we can keep backward compatibility? If not, can you add a note to the changelog? For example note, see: google provider https://github.com/apache/airflow/blob/main/airflow/providers/google/CHANGELOG.rst

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mik-laj I dont think it was working before, the file parameter. I thought I fixed the file-content in an earlier PR, but the passing file was also broken.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please let me know , I can add to CHANGELOG, but as I mentioned before, for files, we need to open the file and pass the bufferedreader to Slack API, it was not done before

@potiuk
Copy link
Member

potiuk commented Aug 9, 2021

Some related slack tests are failing. Can you please rebase and fix those ?

@subkanthi
Copy link
Contributor Author

subkanthi commented Aug 9, 2021

Some related slack tests are failing. Can you please rebase and fix those ?

Thanks @potiuk , Updated, classic case of not digging deeper and assuming that the failure is not related to the change.

@eladkal
Copy link
Contributor

eladkal commented Aug 10, 2021

@subkanthi it's probably related because the failing tests are of Slack

=================================== FAILURES ===================================
  _________ TestSlackAPIFileOperator.test_api_call_params_with_file_args _________
  
  self = <tests.providers.slack.operators.test_slack.TestSlackAPIFileOperator testMethod=test_api_call_params_with_file_args>
  mock_hook = <MagicMock name='SlackHook' id='139893250056768'>
  
      @mock.patch('airflow.providers.slack.operators.slack.SlackHook')
      def test_api_call_params_with_file_args(self, mock_hook):
          test_slack_conn_id = 'test_slack_conn_id'
      
          slack_api_post_operator = SlackAPIFileOperator(
              task_id='slack', slack_conn_id=test_slack_conn_id, file='./test.csv', filetype='csv'
          )
      
  >       slack_api_post_operator.execute()
  
  tests/providers/slack/operators/test_slack.py:215: 
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
  
  self = <Task(SlackAPIFileOperator): slack>, kwargs = {}
  slack = <MagicMock name='SlackHook()' id='139893328790136'>
  
      def execute(self, **kwargs):
          """
          The SlackAPIOperator calls will not fail even if the call is not unsuccessful.
          It should not prevent a DAG from completing in success
          """
          slack = SlackHook(token=self.token, slack_conn_id=self.slack_conn_id)
      
          # If file content is passed.
          if self.content is not None:
              self.api_params = {
                  'channels': self.channel,
                  'content': self.content,
                  'initial_comment': self.initial_comment,
              }
              slack.call(self.method, data=self.api_params)
          # If file name is passed.
          elif self.file is not None:
              self.api_params = {
                  'channels': self.channel,
                  'filename': self.file,
                  'filetype': self.filetype,
                  'initial_comment': self.initial_comment,
              }
  >           with open(self.file, "rb") as file_name:
  E           FileNotFoundError: [Errno 2] No such file or directory: './test.csv'
  
  airflow/providers/slack/operators/slack.py:242: FileNotFoundError

@subkanthi
Copy link
Contributor Author

@subkanthi it's probably related because the failing tests are of Slack

=================================== FAILURES ===================================
  _________ TestSlackAPIFileOperator.test_api_call_params_with_file_args _________
  
  self = <tests.providers.slack.operators.test_slack.TestSlackAPIFileOperator testMethod=test_api_call_params_with_file_args>
  mock_hook = <MagicMock name='SlackHook' id='139893250056768'>
  
      @mock.patch('airflow.providers.slack.operators.slack.SlackHook')
      def test_api_call_params_with_file_args(self, mock_hook):
          test_slack_conn_id = 'test_slack_conn_id'
      
          slack_api_post_operator = SlackAPIFileOperator(
              task_id='slack', slack_conn_id=test_slack_conn_id, file='./test.csv', filetype='csv'
          )
      
  >       slack_api_post_operator.execute()
  
  tests/providers/slack/operators/test_slack.py:215: 
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
  
  self = <Task(SlackAPIFileOperator): slack>, kwargs = {}
  slack = <MagicMock name='SlackHook()' id='139893328790136'>
  
      def execute(self, **kwargs):
          """
          The SlackAPIOperator calls will not fail even if the call is not unsuccessful.
          It should not prevent a DAG from completing in success
          """
          slack = SlackHook(token=self.token, slack_conn_id=self.slack_conn_id)
      
          # If file content is passed.
          if self.content is not None:
              self.api_params = {
                  'channels': self.channel,
                  'content': self.content,
                  'initial_comment': self.initial_comment,
              }
              slack.call(self.method, data=self.api_params)
          # If file name is passed.
          elif self.file is not None:
              self.api_params = {
                  'channels': self.channel,
                  'filename': self.file,
                  'filetype': self.filetype,
                  'initial_comment': self.initial_comment,
              }
  >           with open(self.file, "rb") as file_name:
  E           FileNotFoundError: [Errno 2] No such file or directory: './test.csv'
  
  airflow/providers/slack/operators/slack.py:242: FileNotFoundError

Yes thanks I noticed that too, cant reproduce it on my local, still checking..

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

the file/file_name meaning is reversed here (and add backwards_compatibility change) - they should be swapped

airflow/providers/slack/operators/slack.py Outdated Show resolved Hide resolved
airflow/providers/slack/operators/slack.py Outdated Show resolved Hide resolved
@subkanthi subkanthi requested a review from potiuk August 15, 2021 20:05
@subkanthi
Copy link
Contributor Author

the file/file_name meaning is reversed here (and add backwards_compatibility change) - they should be swapped

@potiuk can u please check again when u get a chance

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

LGTM

@potiuk potiuk merged commit 2935be1 into apache:main Aug 16, 2021
filename="hello_world.csv",
filetype="csv",
)
with open("test.txt", "rb") as file:
Copy link
Member

Choose a reason for hiding this comment

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

What's changing here? file variable looks unused.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add example DAG for SlackAPIFileOperator
4 participants