mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:21:18 +08:00
FIX: no error when double save post with poll (#13111)
Some plugins hook into Post after save to set custom fields and save again. For example: https://github.com/discourse/discourse-category-experts/blob/main/lib/category_experts/post_handler.rb#L27 Problem is that in case like that `raw_changed?` is false but all callback are triggered. `extracted_polls` is class atribute therefore that should be reset with each attempt. That was causing an error: ``` #<ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_polls_on_post_id_and_name" DETAIL: Key (post_id, name)=(8967, poll) already exists. ```
This commit is contained in:

committed by
GitHub

parent
e18d03a301
commit
942b9126a1
@ -467,6 +467,7 @@ after_initialize do
|
||||
|
||||
after_save do
|
||||
polls = self.extracted_polls
|
||||
self.extracted_polls = nil
|
||||
next if polls.blank? || !polls.is_a?(Hash)
|
||||
post = self
|
||||
|
||||
|
Reference in New Issue
Block a user