Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Check geocoded_point is not None when serializing other locations
Browse files Browse the repository at this point in the history
Prevents an exception from being raised in the serializer when a list item
failed geocoding but was able to be matched to another facility.
  • Loading branch information
jwalgran committed Oct 7, 2019
1 parent a453ab7 commit 1ee3e60
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Removed

### Fixed
Check geocoded_point is not None when serializing other locations [#861](https://github.com/open-apparel-registry/open-apparel-registry/pull/861)

### Security

Expand Down
1 change: 1 addition & 0 deletions src/django/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ def get_other_locations(self, facility):
.filter(is_active=True)
if l.facility_list_item != facility.created_from
if l.facility_list_item.geocoded_point != facility.location
if l.facility_list_item.geocoded_point is not None
if l.facility_list_item.facility_list.is_active
if l.facility_list_item.facility_list.is_public
]
Expand Down
12 changes: 12 additions & 0 deletions src/django/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3584,6 +3584,18 @@ def setUp(self):
confidence=0.85,
results='')

def test_excludes_match_if_geocoded_point_is_none(self):
self.other_list_item.geocoded_point = None
self.other_list_item.save()
response = self.client.get(
'/api/facilities/{}/'.format(self.facility.id)
)
data = json.loads(response.content)
self.assertEqual(
len(data['properties']['other_locations']),
0,
)

def test_serializes_other_match_location_in_facility_details(self):
response = self.client.get(
'/api/facilities/{}/'.format(self.facility.id)
Expand Down

0 comments on commit 1ee3e60

Please sign in to comment.