Skip to content

A platform for community discussion. Free, open, simple.

FIX: Return 200 from `update_tags` when no tag changes are needed (#38440)

Isaac Janzen11cadf114314
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb
index a0c58c79030..4837367c2ae 100644
--- a/app/controllers/topics_controller.rb
+++ b/app/controllers/topics_controller.rb
@@ -505,14 +505,14 @@ class TopicsController < ApplicationController
)
end
- success =
- PostRevisor.new(topic.first_post, topic).revise!(
- current_user,
- { tags: },
- validate_post: false,
- )
+ revisor = PostRevisor.new(topic.first_post, topic)
+ revised = revisor.revise!(current_user, { tags: }, validate_post: false)
- success ? render_serialized(topic, BasicTopicSerializer) : render_json_error(topic)
+ if revised || topic.errors.blank?
+ render_serialized(topic, BasicTopicSerializer)
+ else
+ render_json_error(topic)
+ end
end
def feature_stats
diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb
index aa2f3e13693..8e28d4c4d37 100644
--- a/spec/requests/topics_controller_spec.rb
+++ b/spec/requests/topics_controller_spec.rb
@@ -2362,6 +2362,15 @@ RSpec.describe TopicsController do
end
end
+ it "returns success when updating with empty tags on a topic with no tags" do
+ expect(topic.tags).to be_empty
+
+ put "/t/#{topic.id}/tags.json"
+
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["errors"]).to be_nil
+ end
+
it "can update tags" do
expect do
put "/t/#{topic.id}/tags.json", params: { tags: [{ id: tag.id, name: tag.name }] }