Skip to content

Commit

Permalink
[#820] Fix exception in ProjectUpdateResourceExtra.dehydrate()
Browse files Browse the repository at this point in the history
primary_location_data_for_update() in
ProjectUpdateResourceExtra.dehydrate() throws an unhandled exceltion if
the organisation or project doesn't have a primary location.

Since we don't require orgs to have a location wrap the creation of the
primary_location dics in a try-except and return None if there's no
location.
  • Loading branch information
zzgvh committed Oct 20, 2014
1 parent 83223c9 commit d7d1ecf
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions akvo/api/resources/project_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ def dehydrate(self, bundle):
def primary_location_data_for_update(obj):
""" We need similar data for both the project and the organisation associated with the update
"""
primary_location = dict(obj.primary_location.__dict__)
try:
primary_location = dict(obj.primary_location.__dict__)
except:
return None
# remove Django internal field
primary_location.pop('_state', None)
country_id = primary_location.pop('country_id', None)
Expand All @@ -93,7 +96,6 @@ def primary_location_data_for_update(obj):
# remove Django internal field
country_dict.pop('_state', None)
primary_location['country'].update(country_dict)

return primary_location

def org_data_for_update(organisation):
Expand Down

0 comments on commit d7d1ecf

Please sign in to comment.