Skip to content

Conversation

@simonrupf
Copy link
Contributor

Hi there,

TL;DR: This patch intends to fix the remove_page_attachment_keep_version() method in the Confluence class, so that it only removes (some) of the versions and not the attachment as a whole.

Background: I am faced with a Confluence instance that has been around for some years and for reasons™ had several hundreds of times the exact same versions of most of its attachments uploaded to it by a third party Confluence plugin, over and over again. In order to free up dozens of gigabytes of disk space, I am trying to use this library to iterate over the pages in a particular space and for each attachment found on these pages to delete all versions of the attachments except the most recent ones. The remove_page_attachment_keep_version() method seems to be intend to do just that.

Problem: When using the function with a given attachment and a number of versions to keep (m), it gets a list of all versions (n), then starts a while-loop deleting the version n-m of the attachment, until only m versions remain. Unfortunately the method Confluence.delete_attachment() seems to ignore the version parameter and always deletes the whole attachment. This causes an infinite loop, as it doesn't find the new version count, but gets a 403 error instead as the attachment isn't there anymore.

Partial solution: I noticed the Confluence.delete_attachment_by_id() function just below uses a different API call with an explicit version being required. Since we already have the attachment object including ID available in remove_page_attachment_keep_version() we can fix it by simply using that other deletion method.

Conclusion: This PR doesn't address the non-working version parameter in the Confluence.delete_attachment() method. I didn't touch it, as I don't know what other functionality may rely on it. Maybe it could be rewritten to use the Confluence.delete_attachment_by_id() when a version is provided and otherwise keep using the existing logic? Hope this PR serves to prevent others from deleting their attachments accidentally. Luckily we use testing instances. :-)

@gonchik gonchik merged commit b9140ce into atlassian-api:master Oct 28, 2019
@gonchik
Copy link
Member

gonchik commented Oct 28, 2019

Thanks, Good job!

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