From d354d46ef91dced9e7894bbe63488c9912064937 Mon Sep 17 00:00:00 2001 From: "Alexander M. Waldman" Date: Fri, 16 Feb 2024 21:45:37 -0500 Subject: [PATCH] Add coalesce in opa_only query to accomondate unit parcel addresses (#194) --- ais/api/tests/test_views.py | 4 ++++ ais/models.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ais/api/tests/test_views.py b/ais/api/tests/test_views.py index 808f5927..484e4de2 100644 --- a/ais/api/tests/test_views.py +++ b/ais/api/tests/test_views.py @@ -769,3 +769,7 @@ def test_inherited_tags_from_aggregate_parent_are_lowest(client): response = client.get('/search/901 N PENN ST UNIT F1102') data = json.loads(response.get_data().decode()) assert data['features'][0]['properties']['bin'] == '1032992' + +def test_unit_address_parcel_property_opa_only(client): + response = client.get('/search/1650 N 5TH ST UNIT A?opa_only') + assert_status(response, 200) \ No newline at end of file diff --git a/ais/models.py b/ais/models.py index c02ae12c..fbd6e7d8 100644 --- a/ais/models.py +++ b/ais/models.py @@ -1027,7 +1027,7 @@ def exclude_non_opa(self, should_exclude=True): # it's base's OPA account number. In the case where the # address does not have a base, the base num will be None. (AddressSummary.unit_type != '') & - (AddressSummary.opa_account_num == BaseAddressSummary.opa_account_num) + (AddressSummary.opa_account_num == func.coalesce(BaseAddressSummary.opa_account_num, '')) )) \ .order_by(AddressSummary.opa_address, desc(AddressSummary.street_address == AddressSummary.opa_address)) \ .distinct(AddressSummary.opa_address) @@ -1036,6 +1036,7 @@ def exclude_non_opa(self, should_exclude=True): else: return self + def get_all_parcel_geocode_locations(self, srid=DEFAULT_API_SRID, request=None): geocode_xy_join = self \ @@ -1051,6 +1052,7 @@ def get_all_parcel_geocode_locations(self, srid=DEFAULT_API_SRID, request=None): # return result of query without flag (set i=1 so all geocode_location flags are ignored) return self.get_address_geoms(request=request, i=1) + def get_parcel_geocode_location(self, parcel_geocode_location=None, srid=DEFAULT_API_SRID, request=None): if self.first(): # If request arg parcel_geocode_location is included (and if on_street arg is not),