News Aggregator: NoneType' does not support indexing?

Dear readers,

Hello everyone! My name is Andrea, I am very impressed with many aspects of Anvil, and I am trying to see if I can build a project on this platform.

I am currently going through the docs and tutorials.

I am facing some issues in step 4 (Chapter 5) of the tutorial
/learn/tutorials/database-backed-apps/chapter-5

My app

I have gone through the code of the cloned app line by line.

The error is
TypeError: ‘NoneType’ does not support indexing. Did you initialise all data binding sources before initialising this component?
Error binding [text of category_label] to self.item[‘category’][‘name’]:'NoneType' does not support indexing
at [ArticleView, line 12]called from [Homepage, line 20] called from [Homepage, line 16]

I have read previous posts on this tutorial on the forum, but could not find a solution. Could someone please look into this?

Thank you so much for your attention.

Best wishes,

Andrea

Hi Andrea, and welcome! Please provide a clone link to your app (assuming it doesn’t contain anything confidential), as opposed to a link to the running app. See the instructions here: Anvil Docs | Cloning Apps

2 Likes

Hi Tim

Thank you so much for your kind message.

Yes, the app does not contain anything confidential
https://anvil.works/build#clone:IVAKENH6PTMVPBUV=VKCOYVGXSXAESHXDH27R4FIC

What do you think is causing this error?

At the bottom of this page, you can see the original app

Thank you,

Andrea

Hi @andrea.vivante,

Thanks for providing the clone link.

The error TypeError: ‘NoneType’ does not support indexing was caused by the Data Binding of the category_label in your ArticleView Form trying to use square brackets on something that’s None.

The Data Binding was self.item['category']['name']. In this instance self.item is an article from your database and one of the articles didn’t have a category linked, so the value of self.item['category'] is None. Therefore, trying to use square brackets on it will produce the error you’re seeing.

For more information, my colleague Meredydd explained this in more depth here:

If you add a category to the article row that is missing it, your error will be solved.

3 Likes

Hi Ryan,

Thank you so much for your kind response.

This makes sense, it works! I will look into the validation documentation some more.

Best wishes,

Andrea

3 Likes