atlassian-python-api icon indicating copy to clipboard operation
atlassian-python-api copied to clipboard

Unable to provide filename to attachments stored in memory when using add_attachment_object method

Open jcdbautista opened this issue 2 years ago • 0 comments

In the official Python library for JIRA docs, JIRA's add_attachment method will accept a filename if the attachment is being passed from memory as a StringIO object.

https://jira.readthedocs.io/examples.html#:~:text=%23%20attach%20file%20from%20memory%20(you%20can%20skip%20IO%20operations).%20In%20this%20case%20you%20MUST%20provide%20%60filename%60.

Using the atlassian python API however, there is no way to pass in a file name when usingthe add_attachment_object method.

        if context['ti'].xcom_pull(task_ids='load_configs_and_run_query', key='jira_attach_results') is True:
            filename = '{}.csv'.format(context['dag'].dag_id)
            attachment = StringIO()
            attachment.write(context['ti'].xcom_pull(task_ids='load_configs_and_run_query', key='query_results'))
            getattr(jira,'add_attachment_object')(issue['key'],attachment=attachment)

This results in the file in JIRA always having the name "file" with no extension instead of having a customizable name and extension.

https://atlassian-python-api.readthedocs.io/jira.html#:~:text=jira.add_attachment_object(issue_key%2C%20attachment)

jcdbautista avatar Mar 21 '23 20:03 jcdbautista