Skip to content

Commit 03a949a

Browse files
committed
allow zip to mismatch as long as it's within the same borough
1 parent 21088b5 commit 03a949a

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/meshapi/validation.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,19 @@ def __init__(self, street_address: str, city: str, state: str, zip_code: str):
130130

131131
# For some insane reason this is an integer, so we have to cast it to a string
132132
found_zip = str(nyc_planning_resp["features"][0]["properties"]["postalcode"])
133-
if found_zip != zip_code:
133+
134+
# There's a chance the zip code the member is familiar with has changed.
135+
# To mitigate this, we're gonna continue processing the record as long
136+
# as the zip code is in the same borough.
137+
if NYCZipCodes.get_borough(found_zip) != NYCZipCodes.get_borough(zip_code):
134138
raise AddressError(
135139
f"(NYC) Could not find address '{street_address}, {city}, {state} {zip_code}'. "
136140
f"Zip code ({zip_code}) is incorrect or not within city limits"
137141
)
138142

143+
if found_zip != zip_code:
144+
logging.warning(f"Got a different zip code from geosearch.planninglabs.nyc. {found_zip} != {zip_code}")
145+
139146
addr_props = nyc_planning_resp["features"][0]["properties"]
140147

141148
# Get the rest of the address info

src/meshapi/views/forms.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ def process_join_form(r: JoinFormRequest, request: Optional[Request] = None) ->
199199
logging.warning(f"Changed city: {r.city} != {nyc_addr_info.city}")
200200
changed_info["city"] = nyc_addr_info.city
201201

202+
if r.zip_code != nyc_addr_info.zip:
203+
logging.warning(f"Changed zip_code (still in the same borough): {r.zip_code} != {nyc_addr_info.zip}")
204+
changed_info["zip_code"] = nyc_addr_info.zip
205+
202206
# Let the member know we need to confirm some info with them. We'll send
203207
# back a dictionary with the info that needs confirming.
204208
# This is not a rejection. We expect another join form submission with all
@@ -431,6 +435,8 @@ def process_join_form(r: JoinFormRequest, request: Optional[Request] = None) ->
431435
notify_string += f"Changed street_address: {r.street_address} != {nyc_addr_info.street_address}\n"
432436
if r.city != nyc_addr_info.city:
433437
notify_string += f"Changed city: {r.city} != {nyc_addr_info.city}"
438+
if r.zip_code != nyc_addr_info.zip:
439+
notify_string += f"Changed zip code: {r.zip_code} != {nyc_addr_info.zip}"
434440
notify_admins(notify_string)
435441
else:
436442
logging.info(success_message)

src/meshapi/zips.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from typing import Optional
2+
3+
14
bronx = [
25
"10466",
36
"10468",
@@ -229,8 +232,29 @@
229232
"10306",
230233
]
231234

235+
BRONX = "bronx"
236+
NEW_YORK = "new_york"
237+
KINGS = "kings"
238+
QUEENS = "queens"
239+
RICHMOND = "richmond"
240+
241+
zips = {
242+
BRONX: bronx,
243+
NEW_YORK: new_york,
244+
KINGS: kings,
245+
QUEENS: queens,
246+
RICHMOND: richmond
247+
}
232248

233249
class NYCZipCodes:
234250
@staticmethod
235251
def match_zip(zip: str) -> bool:
236252
return any(zip in a for a in [bronx, new_york, kings, queens, richmond])
253+
254+
@staticmethod
255+
def get_borough(zip_code: str) -> Optional[str]:
256+
for borough, z in zips.items():
257+
if zip_code in z:
258+
return borough
259+
return None
260+

0 commit comments

Comments
 (0)