Hi there!
This error message tells you exactly what has gone wrong, even if there is some Python jargon in there. Let’s pull it apart:
TypeError: ‘NoneType’ does not support indexing
In Python “indexing” is a word for using square brackets on something. This error message means we tried to use square brackets on something that’s None
(the empty value in Python), and that’s not allowed.
while setting self.label_1.text = self.item['user']['email']
Aha! Look at what we’re using square brackets on. If this line exploded, then either self.item
or self.item['user']
is None
.
Given that you said you were linking tables together, my guess is that self.item
is a row from a table with a column called 'user'
which links to a row from the Users table. Am I right? If I am, then this error is probably happening when we try to display a row that isn’t linked to any row from the Users table. (Its user
column is None
– so self.item['user']
is None
, and trying to use square brackets on it will produce an error.)
So, there are two possibilites here:
-
Our code is correct, but we are feeding it bad data. (In this case, the table should never have a row with an empty 'user'
column, and it’s understandable that it throws errors if you give it malformed data.)
If this is the case, we need to edit the database to make sure every row is linked to a user – and fix any code that’s creating rows without users!
-
Our data is correct, and our code should be able to deal with it.
If this is the case, we need to change that expression to be able to cope with self.item['user']
being None
.
Where is this error happening?
in a data binding for self.label_1
Well, that’s where we’ll have to fix it! Open the form that has a data binding on label_1
(it’s probably a template form inside a RepeatingPanel or a DataGrid), and then select label_1
.
The data binding is currently:
self.item['user']['email']
As we’ve seen, this doesn’t work when the 'user'
column is set to None
. But the following code works - it tests whether the 'user'
column is None
before indexing into it, and returns a different message if that column is empty:
self.item['user']['email'] if self.item['user'] is not None else 'No User linked to this row'
I hope this step-by-step guide has helped show how you can walk through error messages like these and make sense of them!