Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit de06255

Browse files
authored
FIX: add safe navigation to serializer include conditions (#1349)
In some rare cases a post can exist without a topic
1 parent 296aa24 commit de06255

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/ai_bot/entry_point.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,16 @@ def inject_into(plugin)
140140
:topic_view,
141141
:is_bot_pm,
142142
include_condition: -> do
143-
object.personal_message && object.topic.custom_fields[TOPIC_AI_BOT_PM_FIELD]
143+
object.topic && object.personal_message &&
144+
object.topic.custom_fields[TOPIC_AI_BOT_PM_FIELD]
144145
end,
145146
) { true }
146147

147148
plugin.add_to_serializer(
148149
:post,
149150
:llm_name,
150151
include_condition: -> do
151-
object.topic.private_message? && object.custom_fields[POST_AI_LLM_NAME_FIELD]
152+
object&.topic&.private_message? && object.custom_fields[POST_AI_LLM_NAME_FIELD]
152153
end,
153154
) { object.custom_fields[POST_AI_LLM_NAME_FIELD] }
154155

0 commit comments

Comments
 (0)