From 9263f81bb30712dd48f4d790fe56cd4d816dbbf6 Mon Sep 17 00:00:00 2001 From: LuisFigueroaG Date: Mon, 19 Oct 2026 21:31:30 -0300 Subject: [PATCH] [Confluence] ConfluenceV2: send the body representation in create_page/update_page create_page() and update_page() sent the page body as {"storage": {"value": "..."}} and only added "representation" when the caller passed it, while the comment and custom content methods always send it. #1683 reports a 500 with no error detail from both calls on Confluence Cloud. The representation now defaults to body_format, so the body goes out as {"storage": {"value": "...", "representation": "storage"}}. --- atlassian/confluence/cloud/cloud.py | 10 ++-------- tests/test_confluence_v2.py | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/atlassian/confluence/cloud/cloud.py b/atlassian/confluence/cloud/cloud.py index 9989b286a..563d4e905 100644 --- a/atlassian/confluence/cloud/cloud.py +++ b/atlassian/confluence/cloud/cloud.py @@ -466,13 +466,9 @@ def create_page( "spaceId": space_id, "status": status, "title": title, - "body": {body_format: {"value": body, "representation": representation}}, + "body": {body_format: {"value": body, "representation": representation or body_format}}, } - # Remove representation field if None - if representation is None: - del data["body"][body_format]["representation"] - # Add parent ID if provided if parent_id: data["parentId"] = parent_id @@ -552,9 +548,7 @@ def update_page( data["status"] = status if body: - data["body"] = {body_format: {"value": body}} - if representation: - data["body"][body_format]["representation"] = representation + data["body"] = {body_format: {"value": body, "representation": representation or body_format}} if parent_id: data["parentId"] = parent_id diff --git a/tests/test_confluence_v2.py b/tests/test_confluence_v2.py index bb7c3fcc5..84133041e 100644 --- a/tests/test_confluence_v2.py +++ b/tests/test_confluence_v2.py @@ -222,7 +222,7 @@ def test_create_page(self, mock_post): "spaceId": "SPACE123", "status": "current", "title": "New Page", - "body": {"storage": {"value": "

This is the content

"}}, + "body": {"storage": {"value": "

This is the content

", "representation": "storage"}}, } mock_post.assert_called_once_with("api/v2/pages", data=expected_data) self.assertEqual(response, mock_response) @@ -247,7 +247,7 @@ def test_create_page_with_parent(self, mock_post): "spaceId": "SPACE123", "status": "current", "title": "New Child Page", - "body": {"storage": {"value": "

This is a child page

"}}, + "body": {"storage": {"value": "

This is a child page

", "representation": "storage"}}, "parentId": "PARENT123", } mock_post.assert_called_once_with("api/v2/pages", data=expected_data) @@ -392,7 +392,7 @@ def test_update_page(self, mock_put, mock_get_page): "id": "123", "title": "Updated Page", "version": {"number": 2, "message": "Updated via Python API"}, - "body": {"storage": {"value": "

Updated content

"}}, + "body": {"storage": {"value": "

Updated content

", "representation": "storage"}}, } mock_put.assert_called_once_with("api/v2/pages/123", data=expected_data) self.assertEqual(response, mock_response) @@ -448,12 +448,25 @@ def test_update_page_with_parent_id(self, mock_put): "id": "123", "title": "Moved Page", "version": {"number": 4, "message": "Updated via Python API"}, - "body": {"storage": {"value": "

Content

"}}, + "body": {"storage": {"value": "

Content

", "representation": "storage"}}, "parentId": "456", } mock_put.assert_called_once_with("api/v2/pages/123", data=expected_data) self.assertEqual(response, mock_response) + @patch("atlassian.confluence.cloud.ConfluenceCloud.put") + def test_update_page_body_representation_follows_body_format(self, mock_put): + mock_put.return_value = {"id": "123"} + + self.confluence_v2.update_page(page_id="123", body='{"type": "doc"}', body_format="atlas_doc_format", version=1) + + expected_data = { + "id": "123", + "version": {"number": 2, "message": "Updated via Python API"}, + "body": {"atlas_doc_format": {"value": '{"type": "doc"}', "representation": "atlas_doc_format"}}, + } + mock_put.assert_called_once_with("api/v2/pages/123", data=expected_data) + def test_update_page_invalid_body_format(self): # Test invalid body_format with self.assertRaises(ValueError):