fix: Handle both atom and string keys in weather view packet comparison

The weather view was crashing with KeyError when receiving packets with
string keys instead of atom keys. This was happening when packets were
broadcast from different parts of the system.

Changes:
- Updated should_update_weather? to handle both atom and string keys
- Added proper nil checking for received_at timestamps
- Handle string timestamp comparisons as well as DateTime comparisons

This prevents crashes when the weather view receives packets with
inconsistent key types from PubSub broadcasts.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Graham McIntire 2025-08-03 15:46:12 -05:00
parent 6e504f7209
commit 9b147101e1
No known key found for this signature in database

View file

@ -93,7 +93,23 @@ defmodule AprsmeWeb.WeatherLive.CallsignView do
defp should_update_weather?(current_packet, new_packet) do
# Only update if the new packet is actually newer
DateTime.after?(new_packet.received_at, current_packet.received_at)
# Handle both atom and string keys
new_received_at = Map.get(new_packet, :received_at) || Map.get(new_packet, "received_at")
current_received_at = Map.get(current_packet, :received_at) || Map.get(current_packet, "received_at")
case {new_received_at, current_received_at} do
{nil, _} ->
false
{_, nil} ->
true
{new_time, current_time} when is_binary(new_time) and is_binary(current_time) ->
new_time > current_time
{new_time, current_time} ->
DateTime.after?(new_time, current_time)
end
end
defp update_weather_data(socket) do