From b143412be473bacb50bad4c0ef8909d6a4717b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Thu, 19 Nov 2020 17:31:21 +0100 Subject: [PATCH] DEV: skip_jobs when seeding topics (#11289) Don't raise an exception when creating a post inside a transaction in import_mode. --- lib/post_creator.rb | 6 ++++-- lib/seed_data/topics.rb | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/post_creator.rb b/lib/post_creator.rb index ab3ad240f21..d38d76e8b79 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -199,8 +199,10 @@ class PostCreator end def create - if !Rails.env.test? && ActiveRecord::Base.connection.open_transactions > 0 && !@opts[:skip_jobs] - raise "You must use 'skip_jobs = true' when creating a post inside a transaction, otherwise jobs won't run properly." + if !Rails.env.test? && !@opts[:import_mode] + if ActiveRecord::Base.connection.open_transactions > 0 && !@opts[:skip_jobs] + raise "You must use 'skip_jobs = true' when creating a post inside a transaction, otherwise jobs won't run properly." + end end if valid? diff --git a/lib/seed_data/topics.rb b/lib/seed_data/topics.rb index f019ec1be63..f97629a4d92 100644 --- a/lib/seed_data/topics.rb +++ b/lib/seed_data/topics.rb @@ -131,6 +131,7 @@ module SeedData Discourse.system_user, title: title, raw: raw, + skip_jobs: true, skip_validations: true, category: category&.id ) @@ -139,6 +140,7 @@ module SeedData PostCreator.create!( Discourse.system_user, raw: first_reply_raw(title), + skip_jobs: true, skip_validations: true, topic_id: post.topic_id )