Fix: Critical filtering bugs - missing data handling

Fixed two critical bugs in filter_deals_by_criteria():

Bug #1: CRASH on None property type
- Issue: Code called .lower() on None when propertyTypeDescription was null
- Impact: Would crash MCP tool in production with incomplete data
- Fix: Check if deal_type is None/empty before calling .lower()

Bug #2: Missing data passes through filters
- Issue: Deals with None/missing values passed filters when they shouldn't
- Example: Filtering by area=60-70 would include deals with assetArea=None
- Impact: get_valuation_comparables returned inflated results with bad data
- Fix: Explicitly check for None when filter is active and exclude those deals

Changes:
- Property type filter: Check for None/empty before normalization
- Area filter: Exclude deals with missing area when min/max_area specified
- Room filter: Exclude deals with missing rooms when min/max_rooms specified
- Price filter: Exclude deals with missing price when min/max_price specified
- Invalid data: Changed from 'pass' to 'continue' to exclude bad data

Added 6 comprehensive unit tests:
- test_filter_excludes_missing_property_type
- test_filter_excludes_missing_area
- test_filter_excludes_missing_rooms
- test_filter_excludes_missing_price
- test_filter_excludes_invalid_numeric_data
- test_filter_allows_missing_data_when_no_filter

This fixes the E2E issue where get_valuation_comparables was returning
incomplete results. Now filters properly exclude deals with missing data.

Test results: 34/34 passing (6 new tests added)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Nitzan Pomerantz
2025-10-25 00:08:05 +03:00
parent c19af4cd4e
commit ee0b9466d4
2 changed files with 118 additions and 9 deletions
+19 -9
View File
@@ -842,6 +842,10 @@ class GovmapClient:
deal_type = deal.get(
"propertyTypeDescription", deal.get("assetTypeHeb", "")
)
# Skip deals with missing property type data when filter is active
if not deal_type:
continue
# Normalize both strings for flexible matching
property_type_normalized = property_type.lower().strip()
deal_type_normalized = deal_type.lower().strip()
@@ -852,8 +856,10 @@ class GovmapClient:
continue
# Room count filter
rooms = deal.get("assetRoomNum")
if rooms is not None:
if min_rooms is not None or max_rooms is not None:
rooms = deal.get("assetRoomNum")
if rooms is None:
continue # Skip deals with missing room data when filter is active
try:
rooms = float(rooms)
if min_rooms is not None and rooms < min_rooms:
@@ -861,11 +867,13 @@ class GovmapClient:
if max_rooms is not None and rooms > max_rooms:
continue
except (TypeError, ValueError):
pass # Skip deals with invalid room data
continue # Skip deals with invalid room data when filter is active
# Price filter
price = deal.get("dealAmount")
if price is not None:
if min_price is not None or max_price is not None:
price = deal.get("dealAmount")
if price is None:
continue # Skip deals with missing price data when filter is active
try:
price = float(price)
if min_price is not None and price < min_price:
@@ -873,11 +881,13 @@ class GovmapClient:
if max_price is not None and price > max_price:
continue
except (TypeError, ValueError):
pass # Skip deals with invalid price data
continue # Skip deals with invalid price data when filter is active
# Area filter
area = deal.get("assetArea")
if area is not None:
if min_area is not None or max_area is not None:
area = deal.get("assetArea")
if area is None:
continue # Skip deals with missing area data when filter is active
try:
area = float(area)
if min_area is not None and area < min_area:
@@ -885,7 +895,7 @@ class GovmapClient:
if max_area is not None and area > max_area:
continue
except (TypeError, ValueError):
pass # Skip deals with invalid area data
continue # Skip deals with invalid area data when filter is active
# Floor filter
floor_str = deal.get("floorNo", "")