Skip to content

Commit a0a7f8d

Browse files
authored
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.
1 parent ca9f0e0 commit a0a7f8d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/discourse_data_explorer/data_explorer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def self.extra_data_pluck_fields
115115
},
116116
topic: {
117117
class: Topic,
118-
fields: %i[id title slug posts_count],
118+
fields: %i[id title slug posts_count locale],
119119
serializer: BasicTopicSerializer,
120120
},
121121
group: {

spec/data_explorer_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@
8787
_, colrender = DiscourseDataExplorer::DataExplorer.add_extra_data(result[:pg_result])
8888
expect(colrender).to eq({ 1 => "json" })
8989
end
90+
91+
describe "serializing models to serializer" do
92+
it "serializes correctly to BasicTopicSerializer for topic relations" do
93+
topic = Fabricate(:topic, locale: "ja")
94+
query = Fabricate(:query, sql: "SELECT id AS topic_id FROM topics WHERE id = #{topic.id}")
95+
96+
pg_result = described_class.run_query(query)[:pg_result]
97+
relations, _ = DiscourseDataExplorer::DataExplorer.add_extra_data(pg_result)
98+
99+
expect {
100+
records = relations[:topic].object
101+
records.map { |t| BasicTopicSerializer.new(t, root: false).as_json }
102+
}.not_to raise_error
103+
end
104+
end
90105
end
91106
end
92107
end

0 commit comments

Comments
 (0)