Polls with duplicate choices not migrating properly

Hi, my Discourse instance failed to upgrade recently until I made a specific manual change to the database. I narrowed it down to this commit:

Specifically the index_poll_options_on_poll_id_and_digest unique index which requires each option’s digest (generated from the option text) to be unique from option to option. In other words, if your poll is “what color is the sky” with options “blue” and “blue”, the insert will fail. (My database is imported from PHPBB3 which is why these things might be allowed to have existed before). If that index fails, it aborts the rails migration part of the container rebuild, leaving the site in a broken state.

Solutions I recommend:
Update the plugins/poll/db/post_migrate/20180820080623_migrate_polls_data.rb file to merge duplicate options and their votes into one option.
Remove the requirement that options must be unique.


Sure, I’ll merge the options and votes.


Hi, since it appears that I have the same issue, can you tell me how you made the change in your database (I guess I just have to rename a duplicated option?)?

1 Like

Hi. From what I can remember, poll data was stored as a json blob in the posts table, in the column post_custom_fields. The “digest” hash that you see reported in the migration error message is copied exactly from the id in the options list of this json blob.

So an easy way to locate the offending poll would be to find any post_custom_fields rows that contain the reported digest. As far as I remember I just copied the json blob to a separate document, adjusted it as needed (merged my two options into one and added the votes together), then updated the table with the new blob.

Unfortunately I didn’t keep my notes and my database has the post-migration schema, so I can’t provide any useful SQL queries that are guaranteed to work, but hopefully my memory is accurate and this is a helpful start. I got lucky and only 1 poll out of ~2700 topics had this issue.

1 Like

I reviewed manually all my polls since I had only between 200 and 300.

Only one which had “sort of” cloned values.
The two values were:
- ou
+ ou

But I think that the minus and plus sign weren’t parsed as being part of the option text, hence the detected duplication. I’m not 100% sure but that’s the closest duplicated options I saw.
I should try to rebuild since I have changed the options texts.
Would that do the trick?

I also have another question.
When I did my rebuild, it failed and my forum wasn’t working anymore. I restarted the docker container and I went to sleep and on the morning my forum was working, while not being updated: I guess it was because I restarted the docker container before going to sleep?
Is that supposed to work that way? If a rebuild doesn’t work, you’re not facing a broken forum and you can restart the docker container so it allows running the pre-rebuild, working forum?

1 Like