md2notion icon indicating copy to clipboard operation
md2notion copied to clipboard

'list' object has no attribute 'add_new'

Open Adawg4 opened this issue 4 years ago • 4 comments

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?

Adawg4 avatar Jun 30 '21 18:06 Adawg4

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

Cobertos avatar Jun 30 '21 20:06 Cobertos

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

Adawg4 avatar Jul 07 '21 22:07 Adawg4

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 avatar Jul 20 '21 17:07 Adawg4

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!

Adawg4 avatar Aug 07 '21 18:08 Adawg4