From 1ee3e60b82deeb07b079e639195eabd786d9b6de Mon Sep 17 00:00:00 2001 From: Justin Walgran Date: Mon, 7 Oct 2019 09:20:30 -0700 Subject: [PATCH] Check geocoded_point is not None when serializing other locations Prevents an exception from being raised in the serializer when a list item failed geocoding but was able to be matched to another facility. --- CHANGELOG.md | 1 + src/django/api/serializers.py | 1 + src/django/api/tests.py | 12 ++++++++++++ 3 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb6670649..aeb9a2b8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/django/api/serializers.py b/src/django/api/serializers.py index dea438f71..75b251b7a 100644 --- a/src/django/api/serializers.py +++ b/src/django/api/serializers.py @@ -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 ] diff --git a/src/django/api/tests.py b/src/django/api/tests.py index 8f7eb9742..83959d659 100644 --- a/src/django/api/tests.py +++ b/src/django/api/tests.py @@ -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)