Reputation: 1382
ctx['location_ids'] = vals['location_ids']
I have a large function so I will not post it here, but the problem is when vals['location_ids']
have values as integer everything works smooth, but sometimes there are no values in vals['location_ids']
so it is False
, and when it is False
I get error.
ctx['location_ids'] = vals['location_ids']
TypeError: 'bool' object has no attribute '__getitem__'
how can I avoid it, maybe add hasattr?
Upvotes: 0
Views: 46
Reputation: 3156
you should try to check first it's dictionary
if isinstance(vals, dict):
ctx['location_ids'] = vals.get('location_ids', None)
Upvotes: 1