Fix bug sending None to subscribers.

When a packet was seen twice on MQTT we would send a None packet in the
uplinked packets list after the first time it was seen.
This commit is contained in:
Jason Michalski
2024-05-09 20:35:40 -07:00
parent 3f09d9b649
commit daa0d8b82e
+5 -4
View File
@@ -16,7 +16,9 @@ async def process_envelope(topic, env):
async with database.async_session() as session:
result = await session.execute(select(Packet).where(Packet.id == env.packet.id))
if not result.scalar_one_or_none():
new_packet = False
packet = result.scalar_one_or_none()
if not packet:
new_packet = True
packet = Packet(
id=env.packet.id,
@@ -27,8 +29,7 @@ async def process_envelope(topic, env):
import_time=datetime.datetime.utcnow(),
)
session.add(packet)
else:
packet = None
result = await session.execute(
select(PacketSeen).where(
PacketSeen.packet_id == env.packet.id,
@@ -87,7 +88,7 @@ async def process_envelope(topic, env):
session.add(node)
await session.commit()
if packet:
if new_packet:
await packet.awaitable_attrs.to_node
await packet.awaitable_attrs.from_node
notify.notify_packet(packet.to_node_id, packet)