-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Bug Description
The bot crashes when the !check command is executed in a channel that monitors a city target. The root cause is a ValueError in the _process_target method within src/cogs/runner.py.
This happens because the runner code expects the target_name field for city targets to contain comma-separated coordinates (e.g., "30.26715,-97.74306"), but the database contains the city's name as a string (e.g., "Austin, Texas, US"). The code then attempts to convert the string "Austin" into a float, causing the crash.
Evidence
Log Output:
ValueError: could not convert string to float: 'Austin'
Database Analysis:
An inspection of the production database reveals that for target_type = 'city', the target_name column stores the city name, and the location_id column incorrectly stores the coordinates.
-- Example of malformed data
SELECT id, target_type, target_name, location_id FROM monitoring_targets WHERE target_type = 'city' LIMIT 1;
-- Result: 1|city|Austin, Texas, US|30.26715,-97.74306Root Cause
The issue stems from the command that adds city monitors (!add city). This command appears to be storing the city name and coordinates in the wrong columns (target_name and location_id respectively) and is setting the target_type to city instead of the correct latlong type after geocoding.
Proposed Solution
A complete fix requires two main actions:
-
Code Fix: Modify the
!add citycommand logic.- It should perform geocoding on the provided city name.
- It must save the result as a
latlongtarget, storing the coordinates in thetarget_namefield. - The
target_typeshould be set tolatlong, notcity.
-
Data Migration: A migration script is needed to correct the existing malformed data in the
monitoring_targetstable.- The script should identify all records where
target_type = 'city'. - For each record, it should copy the coordinates from the
location_idcolumn to thetarget_namecolumn. - It should then update the
target_typefromcitytolatlong. - Finally, it should set the
location_idtoNULLfor these records.
- The script should identify all records where
This two-pronged approach will resolve the immediate crash and prevent the issue from recurring.