Skip to content

get_child_nodes("pages", ...) tries to load chapters as pages #30

Closed
@Snaptraks

Description

@Snaptraks

I am trying to use the exporter but I encountered a problem where it tries to get a page by ID, but is actually using a chapter ID and returns a 404 and crashes.
The method is
https://github.com/homeylab/bookstack-file-exporter/blob/main/bookstack_file_exporter/exporter/exporter.py#L143

The book in question is not in a shelf, contains 4 Chapters, some without pages.

I modified NodeExporter._get_children in exporter.py to print the parent's children, and the offending one looks like

{'book_id': 1,
 'created_at': '2023-12-06T13:43:48.000000Z',
 'id': 3,
 'name': 'Embrace2',
 'pages': [{'book_id': 1,
            'chapter_id': 3,
            'created_at': '2023-12-08T20:10:06.000000Z',
            'draft': False,
            'id': 13,
            'name': 'Embrace 2',
            'priority': 1,
            'slug': 'embrace-2',
            'template': False,
            'updated_at': '2023-12-08T20:10:16.000000Z',
            'url': '<base_url>/books/devices/page/embrace-2'}],
 'priority': 1,
 'slug': 'embrace2',
 'type': 'chapter',
 'updated_at': '2023-12-06T13:44:36.000000Z',
 'url': '<base_url>/books/devices/chapter/embrace2'}

and the child_url is <base_url>/api/pages/3

Notice how it is using the chapter ID to get a page from the API, a page that was probably deleted when setting up the Bookstack isntance.

The traceback I am getting is

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\p0129085\AppData\Local\miniconda3\envs\bookstack\Scripts\bookstack-file-exporter.exe\__main__.py", line 7, in <module>
  File "C:\Users\p0129085\AppData\Local\miniconda3\envs\bookstack\Lib\site-packages\bookstack_file_exporter\__main__.py", line 12, in main
    run.exporter(args)
  File "C:\Users\p0129085\AppData\Local\miniconda3\envs\bookstack\Lib\site-packages\bookstack_file_exporter\run.py", line 36, in exporter
    page_nodes: Dict[int, Node] = export_helper.get_all_pages(book_nodes)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\p0129085\AppData\Local\miniconda3\envs\bookstack\Lib\site-packages\bookstack_file_exporter\exporter\exporter.py", line 147, in get_all_pages
    page_nodes: Dict[int, Node] = self.get_child_nodes("pages", book_nodes)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\p0129085\AppData\Local\miniconda3\envs\bookstack\Lib\site-packages\bookstack_file_exporter\exporter\exporter.py", line 84, in get_child_nodes
    return self._get_children(base_url, parent_nodes, filter_empty)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\p0129085\AppData\Local\miniconda3\envs\bookstack\Lib\site-packages\bookstack_file_exporter\exporter\exporter.py", line 98, in _get_children
    child_node = Node(child_data, parent)
                 ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\p0129085\AppData\Local\miniconda3\envs\bookstack\Lib\site-packages\bookstack_file_exporter\exporter\node.py", line 38, in __init__
    self.name: str = self.meta['slug']
                     ~~~~~~~~~^^^^^^^^
KeyError: 'slug'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions