Cobertos / md2notion

A better Notion.so Markdown importer
MIT License
657 stars 66 forks source link

'list' object has no attribute 'add_new' #38

Open Adawg4 opened 3 years ago

Adawg4 commented 3 years ago

I am using a custom uploader for the blocks and I give a parent page after determining a collection view page is the object to add a task, event, or etc to.

new_page = parent_page.collection.add_row(title=subject) #this gets created
uploadCustom(markdown_to_upload, new_page) #this sometimes does work but sometimes doesn't because many users are accessing and uploading things to their notion from my app so I don't always know what is getting uploaded.

I receive this whenever editing a collection view and attempt to add a new task. I'm happy to elaborate on the issue if this is not enough info! (This is my first issue made ever on github 😅)

in uploadCustom
uploadBlock(blockDescriptor, notionPage, mdFile, imagePathFunc)
File "/python/lib/python3.6/site-packages/md2notion/upload.py", line 72, in uploadBlock
newBlock = blockParent.children.add_new(blockClass, **blockDescriptor)
AttributeError: 'list' object has no attribute 'add_new'

Any suggestions?

Cobertos commented 3 years ago

Hmm, a full stack trace would help

Is the first snippet how you're actually calling it? I'm not sure if I've ever used a CollectionRowBlock in there (return of add_row). But .children is on ever Block so I'm not quite sure why it'd be a list and not a Children object

Adawg4 commented 3 years ago

Ill get back in a week or two with the trace.... cheers for the fast response!

Adawg4 commented 3 years ago

Here's the traceback! So the goal is to search for the parent collection or block, and if it is a collection, check if any pages or blocks under it exist, and if not, then in this code create a page under a collection_view_page and upload the contents wanted to said page in markdown.

Traceback: Uploading TextBlock, 1/11 (9.1%) 'list' object has no attribute 'add_new'

Traceback (most recent call last):
  File "/workspace/notionsnag.py", line 1080, in notion_snag
    upload4Hitsnag(body, new_page)
  File "/workspace/notionsnag.py", line 230, in upload4Hitsnag
    uploadBlock(blockDescriptor, notionPage, mdFile, imagePathFunc)
  File "/workspace/.heroku/python/lib/python3.6/site-packages/md2notion/upload.py", line 72, in uploadBlock
     newBlock = blockParent.children.add_new(blockClass, **blockDescriptor)
  AttributeError: 'list' object has no attribute 'add_new'

I am using a custom function to add to a file that I have already

#Had to create a custom upload function due to mdFile needing to not be a file path but rather actual text search 
def upload4Hitsnag(mdFile, notionPage, imagePathFunc=None, notionPyRendererCls=NotionPyRenderer):
    """
    Uploads a single markdown file at mdFilePath to Notion.so as a child of
    notionPage.
    @param {file} mdFile The file handle to a markdown file
    @param {NotionBlock} notionPage The Notion.so block to add the markdown to
    @param {callable|None) [imagePathFunc=None] Function taking image source and mdFilePath
    to transform the relative image paths by if necessary (useful if your images are stored in weird
    locations relative to your md file. Should return a pathlib.Path
    @param {NotionPyRenderer} notionPyRendererCls Class inheritting from the renderer
    incase you want to render the Markdown => Notion.so differently
    """
    # Convert the Markdown file
    rendered = convert(mdFile, notionPyRendererCls)

    # Upload all the blocks
    for idx, blockDescriptor in enumerate(rendered):
        pct = (idx+1)/len(rendered) * 100
        print(f"\rUploading {blockDescriptor['type'].__name__}, {idx+1}/{len(rendered)} ({pct:.1f}%)", end='')
        uploadBlock(blockDescriptor, notionPage, mdFile, imagePathFunc)

It is called here:

elif parent_block_type == "collection_view_page": #get correct collection type to know row can be added
    new_page = parent_page.collection.add_row(title=subject)
    upload4Hitsnag(body, new_page)

I hope this helps more, would be happy to elaborate again! Cheers for maintaining this package too btw!

Adawg4 commented 3 years ago

Just saw the potential for rewrite and I think its a good idea for the future! At the moment Im in a bit of a pinch to get a new deploy out and would love to get this error fixed or figure out the bug. I understand this is open source and you are very busy but any feedback or potential solution would be awesome. Cheers!