You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/07/27 04:29:35 UTC

[GitHub] [airflow] subkanthi opened a new pull request #17247: [14168] Fixed SlackAPIFileOperator to upload file and file content.

subkanthi opened a new pull request #17247:
URL: https://github.com/apache/airflow/pull/17247


   Fixes slackApiFileOperator so that both content and file can be uploaded.
   
   closes: #ISSUE


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on a change in pull request #17247: Fixed SlackAPIFileOperator to upload file and file content

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #17247:
URL: https://github.com/apache/airflow/pull/17247#discussion_r679680023



##########
File path: airflow/providers/slack/operators/slack.py
##########
@@ -161,16 +161,26 @@ class SlackAPIFileOperator(SlackAPIOperator):
 
     .. code-block:: python
 
-        slack = SlackAPIFileOperator(
-            task_id="slack_file_upload",
-            dag=dag,
-            slack_conn_id="slack",
-            channel="#general",
-            initial_comment="Hello World!",
-            filename="hello_world.csv",
-            filetype="csv",
-            content="hello,world,csv,file",
-        )
+       # Send file with filename and filetype
+       slack = SlackAPIFileOperator(
+          task_id="slack_file_upload",
+          dag=dag,
+          slack_conn_id="slack",
+          channel="#general",
+          initial_comment="Hello World!",
+          filename="hello_world.csv",
+          filetype="csv"
+       )
+
+       # Send file content
+       slack = SlackAPIFileOperator(
+          task_id="slack_file_upload",
+          dag=dag,
+          slack_conn_id="slack",
+          channel="#general",
+          initial_comment="Hello World!",
+          content="file content in txt",
+       )

Review comment:
       This is also indented wrong. (Sorry about being picky; people are known to copy-paste the examples and this would be very annoying.)
   
   ```suggestion
           # Send file with filename and filetype
           slack = SlackAPIFileOperator(
               task_id="slack_file_upload",
               dag=dag,
               slack_conn_id="slack",
               channel="#general",
               initial_comment="Hello World!",
               filename="hello_world.csv",
               filetype="csv"
           )
   
           # Send file content
           slack = SlackAPIFileOperator(
               task_id="slack_file_upload",
               dag=dag,
               slack_conn_id="slack",
               channel="#general",
               initial_comment="Hello World!",
               content="file content in txt",
           )
   ```




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on a change in pull request #17247: Fixed SlackAPIFileOperator to upload file and file content

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #17247:
URL: https://github.com/apache/airflow/pull/17247#discussion_r678044606



##########
File path: airflow/providers/slack/operators/slack.py
##########
@@ -161,15 +161,25 @@ class SlackAPIFileOperator(SlackAPIOperator):
 
     .. code-block:: python
 
+        # Send file with filename and filetype
         slack = SlackAPIFileOperator(
-            task_id="slack_file_upload",
-            dag=dag,
-            slack_conn_id="slack",
-            channel="#general",
-            initial_comment="Hello World!",
-            filename="hello_world.csv",
-            filetype="csv",
-            content="hello,world,csv,file",
+           task_id="slack_file_upload",

Review comment:
       This is indented by three spaces?




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] subkanthi commented on a change in pull request #17247: Fixed SlackAPIFileOperator to upload file and file content

Posted by GitBox <gi...@apache.org>.
subkanthi commented on a change in pull request #17247:
URL: https://github.com/apache/airflow/pull/17247#discussion_r678331597



##########
File path: airflow/providers/slack/operators/slack.py
##########
@@ -161,15 +161,25 @@ class SlackAPIFileOperator(SlackAPIOperator):
 
     .. code-block:: python
 
+        # Send file with filename and filetype
         slack = SlackAPIFileOperator(
-            task_id="slack_file_upload",
-            dag=dag,
-            slack_conn_id="slack",
-            channel="#general",
-            initial_comment="Hello World!",
-            filename="hello_world.csv",
-            filetype="csv",
-            content="hello,world,csv,file",
+           task_id="slack_file_upload",

Review comment:
       @uranusjr Thats the sample code for the docs, I can fix it.




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] eladkal commented on a change in pull request #17247: Fixed SlackAPIFileOperator to upload file and file content

Posted by GitBox <gi...@apache.org>.
eladkal commented on a change in pull request #17247:
URL: https://github.com/apache/airflow/pull/17247#discussion_r680373180



##########
File path: airflow/providers/slack/operators/slack.py
##########
@@ -203,13 +213,31 @@ def __init__(
         self.filename = filename
         self.filetype = filetype
         self.content = content
+        self.file_params = {}
         super().__init__(method=self.method, **kwargs)
 
     def construct_api_call_params(self) -> Any:
-        self.api_params = {
-            'channels': self.channel,
-            'content': self.content,
-            'filename': self.filename,
-            'filetype': self.filetype,
-            'initial_comment': self.initial_comment,
-        }
+        if self.content is not None:
+            self.api_params = {
+                'channels': self.channel,
+                'content': self.content,
+                'initial_comment': self.initial_comment,
+            }
+        elif self.filename is not None:
+            self.api_params = {
+                'channels': self.channel,
+                'filename': self.filename,
+                'filetype': self.filetype,
+                'initial_comment': self.initial_comment,
+            }
+            self.file_params = {'file': self.filename}
+
+    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
+        """
+        if not self.api_params:
+            self.construct_api_call_params()
+        slack = SlackHook(token=self.token, slack_conn_id=self.slack_conn_id)
+        slack.call(self.method, data=self.api_params, files=self.file_params)

Review comment:
       Why do we need to pass `filename ` in both `files` & `data` ?
   `api_params` has a `filename` key that contains `self.filename`
   `file_params` has `file` key that contains `self.filename`




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] potiuk merged pull request #17247: Fixed SlackAPIFileOperator to upload file and file content

Posted by GitBox <gi...@apache.org>.
potiuk merged pull request #17247:
URL: https://github.com/apache/airflow/pull/17247


   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] subkanthi commented on a change in pull request #17247: Fixed SlackAPIFileOperator to upload file and file content

Posted by GitBox <gi...@apache.org>.
subkanthi commented on a change in pull request #17247:
URL: https://github.com/apache/airflow/pull/17247#discussion_r678350756



##########
File path: airflow/providers/slack/operators/slack.py
##########
@@ -161,15 +161,25 @@ class SlackAPIFileOperator(SlackAPIOperator):
 
     .. code-block:: python
 
+        # Send file with filename and filetype
         slack = SlackAPIFileOperator(
-            task_id="slack_file_upload",
-            dag=dag,
-            slack_conn_id="slack",
-            channel="#general",
-            initial_comment="Hello World!",
-            filename="hello_world.csv",
-            filetype="csv",
-            content="hello,world,csv,file",
+           task_id="slack_file_upload",

Review comment:
       Fixed.




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #17247: Fixed SlackAPIFileOperator to upload file and file content

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #17247:
URL: https://github.com/apache/airflow/pull/17247#issuecomment-889667579


   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.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org