Error moving posts (solved)

I’m seeing this on one of the discourse I manage, when trying to move two posts to a new topic

ActiveRecord::RecordNotUnique (PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_topic_users_on_topic_id_and_user_id"
DETAIL:  Key (topic_id, user_id)=(266, 177) already exists.
:       INSERT INTO topic_users(user_id, topic_id, notification_level, notifications_reason_id)
           SELECT user_id, 266, 3, 6
             FROM category_users
            WHERE notification_level = 3
              AND category_id = 24
              AND NOT EXISTS(SELECT 1 FROM topic_users WHERE topic_id = 266 AND user_id = category_users.user_id)
)

I’ve upgraded to latest, and still see it.

What can I do here?

confirmed that after a full docker rebuild, the error persists

Anything weird about those posts? Are you moving the first post?

I can’t repro a problem with moving posts on try.discourse.org.

  1. Pick random topic
  2. Move 2 bottom posts to a new topic
  3. Succeeds

Total guess: that user (one whose posts you are moving) doesn’t have permission to be in that category?

I wondered, but now I’m getting the same error on another forum I manage

This is what I get on discourse v1.3.0.beta11 +23

ActiveRecord::RecordNotUnique (PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_topic_users_on_topic_id_and_user_id"
DETAIL:  Key (topic_id, user_id)=(1325, 567) already exists.
:       INSERT INTO topic_users(user_id, topic_id, notification_level, notifications_reason_id)
           SELECT user_id, 1325, 3, 6
             FROM category_users
            WHERE notification_level = 3
              AND category_id = 6
              AND NOT EXISTS(SELECT 1 FROM topic_users WHERE topic_id = 1325 AND user_id = category_users.user_id)
)

I get this when I try to approve a post in the Known Issues Category on my other forum… that forum has no category restrictions at all.

ActiveRecord::RecordNotUnique (PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_topic_users_on_topic_id_and_user_id"
DETAIL:  Key (topic_id, user_id)=(1327, 567) already exists.
:       INSERT INTO topic_users(user_id, topic_id, notification_level, notifications_reason_id)
           SELECT user_id, 1327, 3, 6
             FROM category_users
            WHERE notification_level = 3
              AND category_id = 6
              AND NOT EXISTS(SELECT 1 FROM topic_users WHERE topic_id = 1327 AND user_id = category_users.user_id)
)

I’ve moved my posts about the errors moving posts to this topic.

I’d call it a bug, but there is a chance that this would be due to the default actions I have in our postgres databases. Those are all user based though… if new user, set some prefs, and add watched categories.

We don’t have anything effecting categories or permissions.

What kind of default actions?

1 Like

I set users’ defaults:

I set users’ watch lists

1 Like

This is still going on in my forum… Am I the only one experiencing this?

This was indeed our auto-watch.

the command ended up double-adding watch categories to one of our users. we’ve updated the watch script to help prevent this… but it was no issue with discourse proper

2 Likes