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

Commit 12a3fdc

Browse files
authored
FIX: Don't add only: nil serializing options of data explorer results (#381)
`only: nil` will cause ArraySerializer to overwrite the default Serializer settings, which will cause Topic, Post, etc. to be serialized as empty `{}`. We need to exclude the configuration without only. The current test case only ensures that no error is raised, but does not guarantee the accuracy of the result, which indirectly introduces this bug. Additional tests are added to ensure consistent results.
1 parent 12a26cc commit 12a3fdc

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

lib/discourse_data_explorer/data_explorer.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,9 @@ def self.add_extra_data(pg_result)
198198
.includes(support_info[:include])
199199
.order(:id)
200200

201-
ret[cls] = ActiveModel::ArraySerializer.new(
202-
all_objs,
203-
each_serializer: support_info[:serializer],
204-
only: support_info[:only],
205-
)
201+
opts = { each_serializer: support_info[:serializer] }
202+
opts[:only] = support_info[:only] if support_info[:only]
203+
ret[cls] = ActiveModel::ArraySerializer.new(all_objs, **opts)
206204
end
207205
[ret, col_map]
208206
end

spec/data_explorer_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@
100100
records = relations[:topic].object
101101
records.map { |t| BasicTopicSerializer.new(t, root: false).as_json }
102102
}.not_to raise_error
103+
104+
json = relations[:topic].as_json
105+
expect(json).to include(BasicTopicSerializer.new(topic, root: false).as_json)
103106
end
104107

105108
it "chooses the correct serializer for tag_group" do

0 commit comments

Comments
 (0)