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.74306
Root 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 city command logic.
- It should perform geocoding on the provided city name.
- It must save the result as a
latlong target, storing the coordinates in the target_name field.
- The
target_type should be set to latlong, not city.
-
Data Migration: A migration script is needed to correct the existing malformed data in the monitoring_targets table.
- The script should identify all records where
target_type = 'city'.
- For each record, it should copy the coordinates from the
location_id column to the target_name column.
- It should then update the
target_type from city to latlong.
- Finally, it should set the
location_id to NULL for these records.
This two-pronged approach will resolve the immediate crash and prevent the issue from recurring.
Bug Description
The bot crashes when the
!checkcommand is executed in a channel that monitors acitytarget. The root cause is aValueErrorin the_process_targetmethod withinsrc/cogs/runner.py.This happens because the runner code expects the
target_namefield forcitytargets 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:
Database Analysis:
An inspection of the production database reveals that for
target_type = 'city', thetarget_namecolumn stores the city name, and thelocation_idcolumn incorrectly stores the coordinates.Root 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_nameandlocation_idrespectively) and is setting thetarget_typetocityinstead of the correctlatlongtype after geocoding.Proposed Solution
A complete fix requires two main actions:
Code Fix: Modify the
!add citycommand logic.latlongtarget, storing the coordinates in thetarget_namefield.target_typeshould be set tolatlong, notcity.Data Migration: A migration script is needed to correct the existing malformed data in the
monitoring_targetstable.target_type = 'city'.location_idcolumn to thetarget_namecolumn.target_typefromcitytolatlong.location_idtoNULLfor these records.This two-pronged approach will resolve the immediate crash and prevent the issue from recurring.