mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:15:05 +08:00
FIX: Don’t try to serialize associations in PostRevisionSerializer
Some checks are pending
Licenses / run (push) Waiting to run
Linting / run (push) Waiting to run
Tests / core frontend (${{ matrix.browser }}) (Firefox Evergreen) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (system, plugins) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (system, themes) (push) Waiting to run
Tests / core frontend (${{ matrix.browser }}) (Chrome) (push) Waiting to run
Tests / core frontend (${{ matrix.browser }}) (Firefox ESR) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (annotations, core) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (backend, core) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (backend, plugins) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (frontend, plugins) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (frontend, themes) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (system, chat) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (system, core) (push) Waiting to run
Some checks are pending
Licenses / run (push) Waiting to run
Linting / run (push) Waiting to run
Tests / core frontend (${{ matrix.browser }}) (Firefox Evergreen) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (system, plugins) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (system, themes) (push) Waiting to run
Tests / core frontend (${{ matrix.browser }}) (Chrome) (push) Waiting to run
Tests / core frontend (${{ matrix.browser }}) (Firefox ESR) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (annotations, core) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (backend, core) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (backend, plugins) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (frontend, plugins) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (frontend, themes) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (system, chat) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (system, core) (push) Waiting to run
Currently, if an association is added as a tracked field in `PostRevisor`, the `PostRevisionSerializer` class will try to serialize it somehow. This will raise an error as ActiveRecord collection proxies can't be serialized. This patch addresses this issue by skipping any association tracked by the `PostRevisor` class.
This commit is contained in:
parent
3be925e161
commit
5177aef37d
|
@ -219,8 +219,13 @@ class PostRevisionSerializer < ApplicationSerializer
|
|||
|
||||
# Retrieve any `tracked_topic_fields`
|
||||
PostRevisor.tracked_topic_fields.each_key do |field|
|
||||
next if field == :tags
|
||||
latest_modifications[field.to_s] = [topic.public_send(field)] if topic.respond_to?(field)
|
||||
next unless topic.respond_to?(field)
|
||||
topic
|
||||
.public_send(field)
|
||||
.then do |value|
|
||||
next if value.try(:proxy_association)
|
||||
latest_modifications[field.to_s] = [value]
|
||||
end
|
||||
end
|
||||
|
||||
latest_modifications["featured_link"] = [
|
||||
|
|
|
@ -127,4 +127,20 @@ RSpec.describe PostRevisionSerializer do
|
|||
expect(json[:tags_changes]).to_not be_present
|
||||
end
|
||||
end
|
||||
|
||||
context "when some tracked topic fields are associations" do
|
||||
let(:serializer) { described_class.new(post_revision, scope: guardian, root: false) }
|
||||
let(:post_revision) { Fabricate(:post_revision, post:) }
|
||||
let(:guardian) { Discourse.system_user.guardian }
|
||||
|
||||
before do
|
||||
allow(PostRevisor).to receive(:tracked_topic_fields).and_wrap_original do |original_method|
|
||||
original_method.call.merge(allowed_users: -> {}, allowed_groups: -> {})
|
||||
end
|
||||
end
|
||||
|
||||
it "skips them" do
|
||||
expect { serializer.as_json }.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user