FIX: Add new attribute that is required when using the basic topic serializer (#375)

In discourse/discourse#32618 we added the dependency on locales to the basic topic serializer gated behind SiteSetting.experimental_content_localization. This is so that fancy_titles can be rendered in the language of the user.

Error: `ActiveModel::MissingAttributeError (missing attribute 'locale' for Topic)`
This commit adds that dependency to extra_data_pluck_fields which lists fields required from the serializer.
This commit is contained in:
Natalie Tay 2025-05-20 18:54:58 +08:00 committed by GitHub
parent ca9f0e07cb
commit a0a7f8d999
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View File

@ -115,7 +115,7 @@ module ::DiscourseDataExplorer
},
topic: {
class: Topic,
fields: %i[id title slug posts_count],
fields: %i[id title slug posts_count locale],
serializer: BasicTopicSerializer,
},
group: {

View File

@ -87,6 +87,21 @@ describe DiscourseDataExplorer::DataExplorer do
_, colrender = DiscourseDataExplorer::DataExplorer.add_extra_data(result[:pg_result])
expect(colrender).to eq({ 1 => "json" })
end
describe "serializing models to serializer" do
it "serializes correctly to BasicTopicSerializer for topic relations" do
topic = Fabricate(:topic, locale: "ja")
query = Fabricate(:query, sql: "SELECT id AS topic_id FROM topics WHERE id = #{topic.id}")
pg_result = described_class.run_query(query)[:pg_result]
relations, _ = DiscourseDataExplorer::DataExplorer.add_extra_data(pg_result)
expect {
records = relations[:topic].object
records.map { |t| BasicTopicSerializer.new(t, root: false).as_json }
}.not_to raise_error
end
end
end
end
end