TypeError: 'NoneType' .. no attribute '__getitem__'

Hi, I’m using this code do print data from two linked tables, Projects and ProjectGroups:

def myFunc():
  projects = [item for item in app_tables.projects.client_writable_cascade().search()
              if item['Costs']>100]

  return projects

# ...

projects = myFunc()
if projects:
  for p in projects:
    print(p['ProjectName'])
    print(p['ProjectGroup']['GroupName'])    <-- error
    print(p['Owner']['Name'])                <-- error
    print(p['Costs'])

I’m getting strange TypeError: 'NoneType' object has no attribute '__getitem__' error. Interestingly, the data gets printed out, like:

1st project
First group
John
999.0
2nd project
First group
Michael
135.2

and right after that the output window shows the error message, related to the rows I denoted above. These rows are dealing with linked tables.

I’d appreciate any ideas …

Just a stab in the dark (and I’m drunk), but …

is it possible your datatable has a blank entry as it’s last entry? I’ve noticed that can happen sometimes when entering data directly in the datatable.

Also, you point to the two error lines, yet your output example doesn’t show a final ProjectName before erroring out. So if the project name doesn’t show, how come the projectgroup is the first error?

2 Likes

Heck, I did have one empty row, gosh! You can barely notice it!

The output is OK - when the error happens, it happens for the first row (print(p['ProjectGroup']['GroupName'])), and if I comment it out, it happens also for the second one (print(p['Owner']['Name'])).

It seems that None[some_index] happens in this case …

Thanks, David, for pointing out a possible trouble. And now for the beer … cheers! :beer: :grinning:

2 Likes