From 7ac6c3bdf989d86f1adc8a7a0040ae3f8fcfce03 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Tue, 20 May 2025 07:42:35 +1000 Subject: [PATCH] FIX: add safe navigation to serializer include conditions In some rare cases a post can exist without a topic --- lib/ai_bot/entry_point.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/ai_bot/entry_point.rb b/lib/ai_bot/entry_point.rb index f44ca0dec..444baaa97 100644 --- a/lib/ai_bot/entry_point.rb +++ b/lib/ai_bot/entry_point.rb @@ -140,7 +140,8 @@ def inject_into(plugin) :topic_view, :is_bot_pm, include_condition: -> do - object.personal_message && object.topic.custom_fields[TOPIC_AI_BOT_PM_FIELD] + object.topic && object.personal_message && + object.topic.custom_fields[TOPIC_AI_BOT_PM_FIELD] end, ) { true } @@ -148,7 +149,7 @@ def inject_into(plugin) :post, :llm_name, include_condition: -> do - object.topic.private_message? && object.custom_fields[POST_AI_LLM_NAME_FIELD] + object&.topic&.private_message? && object.custom_fields[POST_AI_LLM_NAME_FIELD] end, ) { object.custom_fields[POST_AI_LLM_NAME_FIELD] }