FIX: Handle deleted categories in post export (#10567)

Fixes a crash when exporting my own archive on Meta.
This commit is contained in:
Kane York 2020-08-31 17:33:28 -07:00 committed by GitHub
parent 594d919d22
commit a1dd761bd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -207,7 +207,8 @@ module Jobs
def piped_category_name(category_id)
return "-" unless category_id
category = Category.find(category_id)
category = Category.find_by(id: category_id)
return "#{category_id}" unless category
categories = [category.name]
while category.parent_category_id && category = category.parent_category
categories << category.name

View File

@ -130,6 +130,18 @@ describe Jobs::ExportUserArchive do
expect(post2['reply_count']).to eq(0)
end
it 'can export a post from a deleted category' do
cat2 = Fabricate(:category)
topic2 = Fabricate(:topic, category: cat2, user: user)
post2 = Fabricate(:post, topic: topic2, user: user)
cat2_id = cat2.id
cat2.destroy!
_, csv_out = make_component_csv
expect(csv_out).to match cat2_id.to_s
puts csv_out
end
end
context 'user_archive_profile' do