# Si è verificato un errore durante lo spostamento dei messaggi

**URL:** https://meta.discourse.org/t/there-was-an-error-moving-posts/342062
**Category:** Bug
**Created:** [12 Dicembre 2024, 1:37pm UTC](https://meta.discourse.org/t/there-was-an-error-moving-posts/342062 "2024-12-12T13:37:33Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mustachianpost](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mustachianpost/32/111646_2.png) [@mustachianpost](https://meta.discourse.org/u/mustachianpost)
#### Post date: [12 Dicembre 2024, 1:37pm UTC](https://meta.discourse.org/t/there-was-an-error-moving-posts/342062/1 "2024-12-12T13:37:33Z")

</div>

Ciao,

Sto riscontrando un problema nello spostamento dei post sulla mia istanza self-hosted (v.3.4.0.beta3-dev)  
Ho controllato il mio plugin delle reazioni e risulta aggiornato (vedi [500 Error: There was an error moving posts](https://meta.discourse.org/t/500-error-there-was-an-error-moving-posts/283387)).

C’è una soluzione consigliata per questo problema (o maggiori dettagli sulla fonte)?

Grazie in anticipo,  
Marc

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [12 Dicembre 2024, 2:15pm UTC](https://meta.discourse.org/t/there-was-an-error-moving-posts/342062/2 "2024-12-12T14:15:53Z")

</div>

> [@mustachianpost](#):
>
> .3.4.0.beta3-dev

Quando hai aggiornato l’ultima volta?

Ci sono state due correzioni questa settimana. L’ultima è stata unita ieri.

> <https://github.com/discourse/discourse/pull/30176>
>
> \## ✨ What's This?
> 
> When moving posts to an existing topic whilst preserving ch…ronological ordering, the second chunk of posts moved can trigger a PostgreSQL error:
> 
> \`\`\`
> PG::UniqueViolation (ERROR: duplicate key value violates unique constraint "post\_timings\_unique"
> DETAIL: Key (topic\_id, post\_number, user\_id)=(36, 29, 1) already exists.
> )
> lib/mini\_sql\_multisite\_connection.rb:109:in \`run'
> app/models/post\_mover.rb:432:in \`copy\_shifted\_post\_timings\_from\_temp'
> app/models/post\_mover.rb:118:in \`handle\_moved\_references'
> app/models/post\_mover.rb:94:in \`move\_posts\_to'
> app/models/post\_mover.rb:28:in \`block in to\_topic'
> app/models/post\_mover.rb:28:in \`to\_topic'
> \`\`\`
> 
> The cause of this error is a little bit silly.
> 
> After a post has been moved from a different topic, a moderator post is inserted into the old topic, pointing to where the post has been moved to.
> 
> This moderator post is ultimately created using \`PostCreator\`, which by default, records a 5000ms Post Timing for that newly created post. Because of how Post Timings are tracked, this timing will be inserted into the \`post\_timings\` table with the same \`topic\_id\`, \`post\_number\`, and \`user\_id\` as the moved post used to have before it was moved.
> 
> Now, when we proceed to moving the next post, \`PostMover.move\_post\_timings\` will look for post timings to move based on whether there's a corresponding entry in the \`moved\_posts\` table. This is where our problem lays: the post that we previously moved has an entry in the \`moved\_posts\` table, but now there's an unexpected entry in \`post\_timings\` that we know doesn't belong to the previously moved post, but it has matching \`topic\_id\`, \`post\_number\`, and \`user\_id\` of the what that moved post used to have, anyway.
> 
> To fix this, we can enforce only matching post IDs that are being moved in this run of \`PostMover\`.
> 
> Internal ref t/142010/5
> 
> \## 👑 Testing
> 
> The simplest way to reproduce this error is:
> 
> \- Create a destination topic.
> \- Create the first source topic, and add a reply to it.
> \- Create a second source topic, and add a reply to it.
> \- Move the reply in the second source topic to the destination topic, remembering to check the “preserve chronological order” option.
> \- Move the reply in the first source topic to the destination, again checking the “preserve chronological order” option.

> <https://github.com/discourse/discourse/pull/30217>
>
> \## ✨ What's This?
> 
> This is a follow-up to #30176.
> 
> When moving multiple firs…t posts to an existing topic whilst preserving chronological ordering, the second move can trigger a PostgreSQL error:
> 
> \`\`\`
> PG::UniqueViolation:
> ERROR: duplicate key value violates unique constraint "post\_timings\_unique"
> DETAIL: Key (topic\_id, post\_number, user\_id)=(1278, 2, 2261) already exists.
> \# ./lib/mini\_sql\_multisite\_connection.rb:109:in \`run'
> \# ./app/models/post\_mover.rb:478:in \`copy\_shifted\_post\_timings\_from\_temp'
> \# ./app/models/post\_mover.rb:137:in \`handle\_moved\_references'
> \# ./app/models/post\_mover.rb:108:in \`move\_posts\_to'
> \# ./app/models/post\_mover.rb:35:in \`block in to\_topic'
> \# ./app/models/post\_mover.rb:35:in \`to\_topic'
> \# ./app/models/topic.rb:1308:in \`move\_posts'
> \`\`\`
> 
> Additionally, if you move from the same topic to a newer destination: it will fail with this error:
> 
> \`\`\`
> PG::CardinalityViolation:
> ERROR: ON CONFLICT DO UPDATE command cannot affect row a second time
> HINT: Ensure that no rows proposed for insertion within the same command have duplicate constrained values.
> \# ./lib/mini\_sql\_multisite\_connection.rb:109:in \`run'
> \# ./app/models/post\_mover.rb:488:in \`copy\_first\_post\_timings'
> \# ./app/models/post\_mover.rb:139:in \`handle\_moved\_references'
> \# ./app/models/post\_mover.rb:108:in \`move\_posts\_to'
> \# ./app/models/post\_mover.rb:35:in \`block in to\_topic'
> \# ./app/models/post\_mover.rb:35:in \`to\_topic'
> \# ./app/models/topic.rb:1308:in \`move\_posts'
> \`\`\`
> 
> Both of these issues can be fixed using the same approach as in #30176: ensuring we only copy post timings for the specific posts that are being moved.
> 
> Internal ref t/142010/15
> 
> \## 👑 Testing
> 
> The first error can be reproduced using this method:
> 
> \- Create two source topics with no replies to either.
> \- Create a destination topic.
> \- Move the single post in the second topic to the destination.
> \- Move the single post in the first topic to the destination.
> 
> The second error can be reproduced with this method:
> 
> \- Create a source topic, and add a reply to it.
> \- Create a destination topic.
> \- Move the reply in the source topic to the destination topic, remembering to check the “preserve chronological order” option.
> \- Move the first post in the source topic to the destination, again checking the “preserve chronological order” option.

---

<div class="post-metadata">

### Author: ![mustachianpost](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mustachianpost/32/111646_2.png) [@mustachianpost](https://meta.discourse.org/u/mustachianpost)
#### Post date: [12 Dicembre 2024, 4:56pm UTC](https://meta.discourse.org/t/there-was-an-error-moving-posts/342062/3 "2024-12-12T16:56:31Z")

</div>

Qualche settimana fa. Ho appena aggiornato e ha risolto il problema 👍  
Grazie per il supporto rapido, l’argomento può essere chiuso.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [12 Dicembre 2024, 6:33pm UTC](https://meta.discourse.org/t/there-was-an-error-moving-posts/342062/4 "2024-12-12T18:33:17Z")

</div>


