FIX: add safe navigation to serializer include conditions (#1349)

In some rare cases a post can exist without a topic
This commit is contained in:
Sam 2025-05-20 07:55:55 +10:00 committed by GitHub
parent 296aa24df1
commit de0625571b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -140,7 +140,8 @@ module DiscourseAi
:topic_view, :topic_view,
:is_bot_pm, :is_bot_pm,
include_condition: -> do 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, end,
) { true } ) { true }
@ -148,7 +149,7 @@ module DiscourseAi
:post, :post,
:llm_name, :llm_name,
include_condition: -> do 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, end,
) { object.custom_fields[POST_AI_LLM_NAME_FIELD] } ) { object.custom_fields[POST_AI_LLM_NAME_FIELD] }