From 49e647e60953f68f54590408dd4f4e13bece0510 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Mon, 4 Aug 2025 10:30:52 -0500 Subject: [PATCH] fix: Handle additional parser fields causing insertion failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The parser is sending fields with different names than our schema: - aprs_messaging? (with question mark) -> convert to aprs_messaging - raw_data -> remove (not in schema) This should fix the remaining packet insertion failures in production. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- lib/aprsme/packet_consumer.ex | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/aprsme/packet_consumer.ex b/lib/aprsme/packet_consumer.ex index b10f650..15cf91c 100644 --- a/lib/aprsme/packet_consumer.ex +++ b/lib/aprsme/packet_consumer.ex @@ -312,6 +312,7 @@ defmodule Aprsme.PacketConsumer do # Apply the same processing as the original store_packet function attrs |> convert_coordinate_field_names() + |> convert_field_names() |> normalize_packet_attrs() |> set_received_at() |> patch_lat_lon_from_data_extended() @@ -392,6 +393,11 @@ defmodule Aprsme.PacketConsumer do |> Map.delete("longitude") |> Map.delete(:latitude) |> Map.delete("latitude") + # Fields with naming mismatches + |> Map.delete(:aprs_messaging?) + |> Map.delete("aprs_messaging?") + |> Map.delete(:raw_data) + |> Map.delete("raw_data") end # Helper functions for coordinate validation and point creation @@ -474,6 +480,23 @@ defmodule Aprsme.PacketConsumer do end end + # Convert field names that don't match our schema + defp convert_field_names(attrs) do + then(attrs, fn a -> + # Convert aprs_messaging? to aprs_messaging + case Map.get(a, :aprs_messaging?) || Map.get(a, "aprs_messaging?") do + nil -> + a + + value -> + a + |> Map.put(:aprs_messaging, value) + |> Map.delete(:aprs_messaging?) + |> Map.delete("aprs_messaging?") + end + end) + end + # Convert latitude/longitude to lat/lon if present at top level defp convert_coordinate_field_names(attrs) do attrs