Repository navigation
[Confluence] Server attach_content: look up the existing attachment by filename - #1701
Open
LuisFigueroaG wants to merge 1 commit into
Open
LuisFigueroaG wants to merge 1 commit into
LuisFigueroaG wants to merge 1 commit into
Conversation
…y filename Since atlassian-api#1666, attach_content() lists the page's attachments without the filename filter that 4.x sent, and only searches the first page of results (50 by default). When the page has more attachments and the file isn't on that page, it tries to create it again and Confluence rejects the upload because the name is already taken. Send params={"filename": name} again so Confluence returns the matching attachment directly.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ConfluenceServer.attach_content()checks whether the file is already on the page withand then looks for the name in
attachments["results"]. That endpoint (GET /rest/api/content/{id}/child/attachment) is paginated withlimitdefaulting to 50, so on a page with more attachments the existing file can be missing from the first page.attach_content()then POSTs it as a new attachment, and Confluence rejects it because an attachment with that name already exists.4.x sent
params={"filename": name}here; it was lost when #1666 replaced the PUT with GET + POST. This adds it back. The endpoint documentsfilenameas a filter that returns only the matching attachment, so the lookup no longer depends on how many files the page has. Thetitle == namecheck and the POST to.../{attachment_id}/datafrom #1687 are unchanged.Fixes #1700
Tests: updated the GET assertion in
test_attach_content_checks_existing_attachments_before_createand addedtest_attach_content_finds_existing_attachment_beyond_first_page, which mocks the session with 50 unrelated attachments on the unfiltered list and expects the update to go to.../att-51/data. Both fail on master. The full pytest suite, mypy, bandit and doc8 pass; flake8 and black only report the two files underexamples/that already fail on master. I haven't run it against a real Confluence Server.