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.
This commit is contained in:
Linca 2025-07-07 08:46:49 +08:00 committed by GitHub
parent 12a26cc821
commit 12a3fdc246
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 5 deletions

View File

@ -198,11 +198,9 @@ module ::DiscourseDataExplorer
.includes(support_info[:include]) .includes(support_info[:include])
.order(:id) .order(:id)
ret[cls] = ActiveModel::ArraySerializer.new( opts = { each_serializer: support_info[:serializer] }
all_objs, opts[:only] = support_info[:only] if support_info[:only]
each_serializer: support_info[:serializer], ret[cls] = ActiveModel::ArraySerializer.new(all_objs, **opts)
only: support_info[:only],
)
end end
[ret, col_map] [ret, col_map]
end end

View File

@ -100,6 +100,9 @@ describe DiscourseDataExplorer::DataExplorer do
records = relations[:topic].object records = relations[:topic].object
records.map { |t| BasicTopicSerializer.new(t, root: false).as_json } records.map { |t| BasicTopicSerializer.new(t, root: false).as_json }
}.not_to raise_error }.not_to raise_error
json = relations[:topic].as_json
expect(json).to include(BasicTopicSerializer.new(topic, root: false).as_json)
end end
it "chooses the correct serializer for tag_group" do it "chooses the correct serializer for tag_group" do