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

[Confluence] Using create_page method with None as body causes 500 Internal Server Error #1345

Open
pauldevlin-smarsh opened this issue Mar 6, 2024 · 0 comments

Comments

@pauldevlin-smarsh
Copy link

pauldevlin-smarsh commented Mar 6, 2024

When using the Confluence API (version 3.5.2), a 500 internal error when trying to send a create_page request to Confluence. A similar issue occurs when using an updated version (3.41.11) which rases the following error:
raise HTTPError(error_msg, response=response) requests.exceptions.HTTPError: com.atlassian.confluence.api.service.exceptions.ServiceException: java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.length()" because "unclean" is null

The following script reproduces the error.

from atlassian import Confluence


confluence = Confluence(
    url=<ATLASSIAN_URL>,
    username=<ATLASSIAN_USER>,
    password=<ATLASSIAN_KEY>
)


def createPageIfNotExists(space,parentId,title):
    print(f'Checking if {space}\\{parentId}\\{title} exists.')
    pageExists = confluence.page_exists(space, title)
    if not pageExists:
        print(f'{space}\{parentId}\{title} does not exist.It will be created.')
        print(f"Creating page with space: {space}, title: {title}, parentId: {parentId}")
        confluence.create_page(space, title, None, parent_id=parentId, type='page', representation='storage', editor='v2')
    pageId = confluence.get_page_id(space, title)
    return pageId


createPageIfNotExists("Test", "123456", "TestPage")

Updating the following line to send "" as the body resolves the issue in both versions:
confluence.create_page(space, title, "", parent_id=parentId, type='page', representation='storage', editor='v2')

The following code could be updated in confluence.py to default the body to "":
def create_page( self, space, title, body="", parent_id=None, type="page", representation="storage", editor=None, full_width=False, ):

This would resolve the issue and since the Atlassian API requires it it will cover scenarios with or without and body of string being sent

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

No branches or pull requests

1 participant