IATI / IATI-Publishing-Statistics

Tables and files presenting different stats for IATI publishers
http://publishingstats.iatistandard.org
4 stars 3 forks source link

Bug fix: Check for None and type(None) in more places #25

Closed odscjames closed 9 months ago

odscjames commented 9 months ago

We saw a crash on live and dev:

  File "/work/IATI-Publishing-Statistics/IATI-Stats/statsrunner/aggregate.py", line 117, in aggregate
    dict_sum_inplace(publisher_total, subtotal)
  File "/work/IATI-Publishing-Statistics/IATI-Stats/statsrunner/aggregate.py", line 29, in dict_sum_inplace
    dict_sum_inplace(d1[k], v)
  File "/work/IATI-Publishing-Statistics/IATI-Stats/statsrunner/aggregate.py", line 37, in dict_sum_inplace
    d1[k] += v
TypeError: unsupported operand type(s) for +=: 'int' and 'NoneType'

Here is a local test you can run that crashes before this commit and doesn't afterwards:

import statsrunner.aggregate
d1 = { "cats": 5, "dogs": 67 }
d2 = { "cats": type(None), "dogs":None }
statsrunner.aggregate.dict_sum_inplace(d1,d2)
d1 = { "cats": 5, "dogs": 67 }
d2 = { "cats": type(None), "dogs":None }
statsrunner.aggregate.dict_sum_inplace(d2,d1)

This PR is masking the root error; why is type(None) suddenly coming through? This however should let processing not crash and carry on

odscjames commented 9 months ago

It would be better to check for int type but i'm not sure what other types are allowed (eg is float?) so as a urgent thing just stopping None crashes is a good start