Skip to content

Conversation

nitram509
Copy link
Contributor

Problem / Observation

Using the method get_attachment_content() returns a str of the content, which corrupts the actual content bytes due to encoding issues.

Usage example (problem showcase)

Assuming, there's a PNG image attached to a ticket, in my use case I want to download the PNG image.

content = jira.get_attachment_content(12345)
with open("content.png", 'wb') as f:
    f.write(content)

This leads to a runtime exception: a bytes-like object is required, not 'str'
IF I try to use text file mode open("content.png", 'w') then the content is broken due to utf-8 encoding, which is obviously not required, but used due to the fact the content object type is str.

Fix

Don't convert an attachment content into a string, e.g. using self.get(url, not_json_response=True)

Impact

  • This PR fixes the issue for all binary attachments and is the correct way how to handle binary attachments - that said, text attachments will work as well.
  • This PR potentially breaks existing integration, IF people tried to use character encoding and somehow build workarounds - chances are minor IMHO, as I was not able to build a workaround for binary data, and only could imagine encoding-workarounds for textual attachments.

Context

  • manually tested with Python 3.12 on Mac OSX (Apple silicon)

Copy link

codecov bot commented Jul 17, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 34.38%. Comparing base (42ed0b0) to head (529335f).
Report is 25 commits behind head on master.

Files with missing lines Patch % Lines
atlassian/jira.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1433   +/-   ##
=======================================
  Coverage   34.38%   34.38%           
=======================================
  Files          46       46           
  Lines        8586     8586           
  Branches     1601     1601           
=======================================
  Hits         2952     2952           
  Misses       5511     5511           
  Partials      123      123           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gonchik gonchik merged commit 795705b into atlassian-api:master Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants