Skip to content

[Confluence] Server attach_content: look up the existing attachment by filename - #1701

Open
LuisFigueroaG wants to merge 1 commit into
atlassian-api:masterfrom
LuisFigueroaG:fix/confluence-attach-content-filename
Open

LuisFigueroaG wants to merge 1 commit into
atlassian-api:masterfrom
LuisFigueroaG:fix/confluence-attach-content-filename

Conversation

@LuisFigueroaG

Copy link
Copy Markdown
Contributor

ConfluenceServer.attach_content() checks whether the file is already on the page with

attachments = self.get(path=path, headers=headers)

and then looks for the name in attachments["results"]. That endpoint (GET /rest/api/content/{id}/child/attachment) is paginated with limit defaulting 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 documents filename as a filter that returns only the matching attachment, so the lookup no longer depends on how many files the page has. The title == name check and the POST to .../{attachment_id}/data from #1687 are unchanged.

Fixes #1700

Tests: updated the GET assertion in test_attach_content_checks_existing_attachments_before_create and added test_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 under examples/ that already fail on master. I haven't run it against a real Confluence Server.

…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

No deployments
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.

attach_content() may miss existing attachments

1 participant