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

Close the file descriptor for add_attachment #957

Merged
merged 4 commits into from May 18, 2021

Conversation

yen3
Copy link
Contributor

@yen3 yen3 commented Jul 31, 2020

If the attachment argument is string, the add_attachment function creates a file descriptor then forget to close it. The patch closes the file descriptor after the post action.

@adehad adehad added bug enhancement Status: Needs Rework PR has been submitted, but changes required. and removed Status: Needs Rework PR has been submitted, but changes required. labels May 2, 2021
@adehad
Copy link
Collaborator

adehad commented May 2, 2021

I think you have addressed the problem correctly, but part of me wonders why this function is structured the way it is.

Probably a future pull request though, so don't worry about it now.
I wonder if this function should only accept a string, and the context manager approach be used to open it the intended way (i.e. "rb" mode etc.), this would make the function a lot clearer.

But perhaps I am missing a use case for when the file would already be open ?

@yen3
Copy link
Contributor Author

yen3 commented May 4, 2021

Hi, @adehad Thanks for your reply.

https://github.com/pycontribs/jira/pull/957/files#diff-442d14b20d591afd0c3de830d2803e30d4816eedc708f9ad129316aa7e5a4a7cL856

The parameter document mentioned that the function could accept a file descriptor. Maybe I misunderstood something.

@adehad
Copy link
Collaborator

adehad commented May 4, 2021

Hi, @adehad Thanks for your reply.

https://github.com/pycontribs/jira/pull/957/files#diff-442d14b20d591afd0c3de830d2803e30d4816eedc708f9ad129316aa7e5a4a7cL856

The parameter document mentioned that the function could accept a file descriptor. Maybe I misunderstood something.

Yep you are correct, i was just rambling to myself haha, sorry for the confusion.

jira/client.py Outdated Show resolved Hide resolved
@studioj
Copy link
Collaborator

studioj commented May 7, 2021

it would be nice if you would add a test uploading for example the README file as file descriptor and as string

@studioj studioj closed this May 8, 2021
@studioj studioj reopened this May 8, 2021
@yen3
Copy link
Contributor Author

yen3 commented May 8, 2021

@studioj Thanks for your review. Remove the unused blocks

studioj
studioj previously approved these changes May 8, 2021
@studioj
Copy link
Collaborator

studioj commented May 11, 2021

@ssbarnea i think this can be merged

@adehad
Copy link
Collaborator

adehad commented May 14, 2021

@yen3 don't suppose you could run tox -e lint over this. It seems like it is just the linting that is causing the checks to fail.

If the attachment is string, the add_attachment function creates a
file descriptor then forget to close it. The patch closes the file
descriptor after the post action.
@yen3
Copy link
Contributor Author

yen3 commented May 16, 2021

@adehad @studioj @ssbarnea Thanks for the review. I try to rebase on the latest master branch so I push the change again. Please review it again. Thank you.

@adehad
Copy link
Collaborator

adehad commented May 16, 2021

@yen3 looks like there is still a minor linting problem, otherwise changes look good to me.

@yen3
Copy link
Contributor Author

yen3 commented May 17, 2021

@adehad Thanks for the review. I try to fix it. Please review it again.

Copy link
Collaborator

@adehad adehad left a comment

Choose a reason for hiding this comment

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

added a minor comment on where we do the cast()

jira/client.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@adehad adehad left a comment

Choose a reason for hiding this comment

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

oops, there's a cheeky black formatting error somewhere here

@yen3
Copy link
Contributor Author

yen3 commented May 17, 2021

@adehad I run black -l 88 client.py to refine the code format.

@adehad adehad requested a review from ssbarnea May 18, 2021 08:58
@ssbarnea ssbarnea merged commit 445d375 into pycontribs:master May 18, 2021
svermeulen pushed a commit to svermeulen/jira that referenced this pull request Oct 31, 2021
* Close the file descriptor for add_attachment

If the attachment is string, the add_attachment function creates a
file descriptor then forget to close it. The patch closes the file
descriptor after the post action.

* Pass a correct type for the variable

* Convert type earliy

* Refine code format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants