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

KeyError: 'title' on confluence.client.Confluence.get_content() #22

Open
justquick opened this issue Sep 19, 2019 · 3 comments
Open

KeyError: 'title' on confluence.client.Confluence.get_content() #22

justquick opened this issue Sep 19, 2019 · 3 comments
Assignees

Comments

@justquick
Copy link

justquick commented Sep 19, 2019

When paginating through the confluence.client.Confluence.get_content() method I am running into a KeyError when trying to fetch the title field from a content response. The rest of the fields in content appear on that record and the rest of my application works just fine except for this one bad item. I feel like title should be a required field or at least be a blank string but now it just blows up in my face. I am running Confluence version 6.15.9

Traceback (most recent call last):
  File "/Users/jquick/.virtualenvs/matrix-7HUYJ2hm/lib/python3.6/site-packages/celery/app/trace.py", line 385, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/Users/jquick/.virtualenvs/matrix-7HUYJ2hm/lib/python3.6/site-packages/celery/app/trace.py", line 648, in __protected_call__
    return self.run(*args, **kwargs)
  File "/Users/jquick/Box/Projects/matrix/confluence_app/tasks.py", line 23, in confluence_spaces
    confluence_space_content(space.key)
  File "/Users/jquick/.virtualenvs/matrix-7HUYJ2hm/lib/python3.6/site-packages/celery/local.py", line 191, in __call__
    return self._get_current_object()(*a, **kw)
  File "/Users/jquick/.virtualenvs/matrix-7HUYJ2hm/lib/python3.6/site-packages/celery/app/trace.py", line 649, in __protected_call__
    return orig(self, *args, **kwargs)
  File "/Users/jquick/.virtualenvs/matrix-7HUYJ2hm/lib/python3.6/site-packages/celery/app/task.py", line 394, in __call__
    return self.run(*args, **kwargs)
  File "/Users/jquick/Box/Projects/matrix/confluence_app/tasks.py", line 31, in confluence_space_content
    for content in client.get_content(ctype, space_key, expand=['history']):
  File "/Users/jquick/.virtualenvs/matrix-7HUYJ2hm/lib/python3.6/site-packages/confluence/client.py", line 139, in _get_paged_results
    yield item_type(result)
  File "/Users/jquick/.virtualenvs/matrix-7HUYJ2hm/lib/python3.6/site-packages/confluence/models/content.py", line 69, in __init__
    self.title = json['title']  # type: str
KeyError: 'title'

The site I am pulling this from is private but here is response content (with some info scrubbed for privacy)

{
    "_expandable": {
        "ancestors": "",
        "body": "",
        "children": "/rest/api/content/12345/child",
        "container": "/rest/api/space/webDomain",
        "descendants": "/rest/api/content/12345/descendant",
        "metadata": "",
        "operations": "",
        "restrictions": "/rest/api/content/12345/restriction/byOperation",
        "space": "/rest/api/space/webDomain",
        "version": ""
    },
    "_links": {
        "edit": "/pages/resumedraft.action?draftId=12345",
        "self": "https://confluence.internal.com/rest/api/content/12345",
        "tinyui": "/x/XXXXX",
        "webui": "/pages/viewpage.action?pageId=12345"
    },
    "extensions": {
        "position": "none"
    },
    "history": {
        "_expandable": {
            "contributors": "",
            "lastUpdated": "",
            "nextVersion": "",
            "previousVersion": ""
        },
        "_links": {
            "self": "https://confluence.internal.com/rest/api/content/12345/history"
        },
        "createdBy": {
            "_expandable": {
                "status": ""
            },
            "_links": {
                "self": "https://confluence.internal.com/rest/api/user?key=0987654321"
            },
            "displayName": "Justin Quick",
            "profilePicture": {
                "height": 48,
                "isDefault": false,
                "path": "/download/attachments/555/user-jquick-ldap-image.png",
                "width": 48
            },
            "type": "known",
            "userKey": "0987654321",
            "username": "jquick"
        },
        "createdDate": "2013-01-10T12:08:49.000-05:00",
        "latest": true
    },
    "id": "12345",
    "status": "current",
    "type": "page"
}
DaveTCode pushed a commit that referenced this issue Sep 19, 2019
According to a test case provided in #22 it is possible
for the title of a confluence page to be unset.

Refs #22
@DaveTCode
Copy link
Owner

Presumably it's somehow possible to have a page with no title in confluence?? Certainly wasn't expecting that when I wrote it.

I've pushed a change but will need to fix the broken travis build environment before I can release.

Since it's annoyingly an API change this will come as 2.0.0 despite it being basically a one line fix.

@DaveTCode DaveTCode self-assigned this Sep 19, 2019
@justquick
Copy link
Author

LGTM, thats exactly what I did locally to fix the issue too.

@justquick
Copy link
Author

Got another problem, since self.title doesnt exist then line 97, in str will break. Suggest setting self.title = 'Untitled' as a default before inspecting json for a title

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

2 participants