Question Answer Plugin

I’ve merged the PR :+1:


This was occurring on all topics, not just QnA ones. We have a ‘Questions’ category when all topics are QnA, and also have the ‘question’ tag to make a topic QnA.

The behavior is slightly different now though, before the sort order they were given fixed them at the bottom of the list, now they are still out of order, but newer posts are below them.

1 Like

Thanks @AJDurant.

One of our clients experienced this issue, so I was able to take a closer look at a dataset where it was occuring. I believe one issue here might be the when topics where a QA tag is removed are handled.

I’ve started a PR that addresses this issue, which @mbcahyono and I will work on

The way to fix the issue for a specific topic is:

./launcher enter app
rails c
topic = Topic.find(<topic_id>) 
topic.posts.each { |p| p.update_columns(sort_order: p.post_number) }

If anyone needs any more hands on help addressing this issue on their server please reach out to me privately and I can help you address it (no charge).

1 Like

Sorry for not responding sooner. I’ve been traveling this week. I can confirm your code above is fixing the individual posts with issues.

I also confirmed that running the following command does NOT fix the problem

rake "posts:reorder_posts[1234]"

Is there a way to run this across all posts - basically loop over all posts?

And you’ve just run rake posts:reorder_posts by itself and it doesn’t work? Please try that again first.

If that doesn’t work you can run this

./launcher enter app
rails c
Post.update_all("sort_order = post_number")

We have figured out what the issue is. It was introduced back in August. We’ll push a fix for it shortly, with a test for the case.


I ran the above command and got the following error

root@REMOVE-web-only:/var/www/discourse# rake posts:reorder_posts
rake aborted!
PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "post_timings_unique"
DETAIL:  Key (topic_id, post_number, user_id)=(1567, 20, 3) already exists.
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-mini-profiler-2.2.0/lib/patches/db/pg.rb:110:in `exec'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-mini-profiler-2.2.0/lib/patches/db/pg.rb:110:in `async_exec'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/mini_sql-0.3/lib/mini_sql/postgres/connection.rb:201:in `run'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/mini_sql-0.3/lib/mini_sql/postgres/connection.rb:173:in `exec'
/var/www/discourse/lib/tasks/posts.rake:368:in `block (3 levels) in <main>'
/var/www/discourse/lib/tasks/posts.rake:351:in `each'
/var/www/discourse/lib/tasks/posts.rake:351:in `block (2 levels) in <main>'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord- `block in transaction'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord- `block in within_new_transaction'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport- `block (2 levels) in synchronize'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport- `handle_interrupt'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport- `block in synchronize'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport- `handle_interrupt'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport- `synchronize'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord- `within_new_transaction'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord- `transaction'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord- `transaction'
/var/www/discourse/lib/tasks/posts.rake:312:in `block in <main>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
Tasks: TOP => posts:reorder_posts
(See full trace by running task with --trace)

I did not run the second command once I saw the duplicate key error thinking that might be a larger issue.

That looks like an issue with your db that’s independent of this, but blocking a fix here. I’ll pm you shortly and we can debug that seperately.


Thanks @angus that all seems to be working correctly now :smiley:

Running latest release and seeing the following errors.

Message (49 copies reported)

Job exception: uninitialized constant Jobs::QaUpdateTopicsPostOrder
Did you mean? Jobs::UpdateTopicPostOrder


/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport- const_get' /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport- block in constantize’
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport- each' /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport- inject’
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport- constantize' /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport- constantize’
/var/www/discourse/app/jobs/base.rb:288:in enqueue' /var/www/discourse/app/jobs/onceoff/onceoff.rb:40:in block in enqueue_all’
/var/www/discourse/app/jobs/onceoff/onceoff.rb:37:in each' /var/www/discourse/app/jobs/onceoff/onceoff.rb:37:in enqueue_all’

Sorry for the issue. Working on it, waiting to be merged:

1 Like

Cool, I’m excited to see this merged and look forward to the fix. Happy Holidays.

What is the role of the “QnA one-to-many format.” setting that can be found in category settings?

It’s a deprecated feature, which we’ll be removing from the QnA Plugin in the near future. That feature now has it’s own dedicated plugin

1 Like

How do you remove your vote? In options, there is a configuration of how much time you have to undo the vote, but I don’t see a way how to actually do that.