# Editing a poll with votes creates inconsistent state

**URL:** https://meta.discourse.org/t/editing-a-poll-with-votes-creates-inconsistent-state/28239
**Category:** Bug
**Tags:** polls
**Created:** [May 2, 2015, 2:31pm UTC](https://meta.discourse.org/t/editing-a-poll-with-votes-creates-inconsistent-state/28239 "2015-05-02T14:31:09Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [May 2, 2015, 2:31pm UTC](https://meta.discourse.org/t/editing-a-poll-with-votes-creates-inconsistent-state/28239/1 "2015-05-02T14:31:09Z")

</div>

**Steps to reproduce**

- Create a new poll
- Vote for an option
- Edit the poll and add another option

**Expected result**  
The poll should show the additional option and the already cast votes should be visible.

**Actual result**  
The additional option is visible and the votes are still there, but the total\_votes are gone which results in invalid results.  
I voted for “Yes” in the following example and then added the “I don’t know” option to it.

_Poll ([view on site](https://meta.discourse.org/t/editing-a-poll-with-votes-creates-inconsistent-state/28239/1))_

* * *

**Bonus bug**  
Same steps as above with the following additional steps:

- Click “Hide results” when the poll is already “destroyed”.
- Vote for another option like “No”.

See the following example for the result of those actions:

_Poll ([view on site](https://meta.discourse.org/t/editing-a-poll-with-votes-creates-inconsistent-state/28239/1))_

---

<div class="post-metadata">

### Author: ![Olefine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/olefine/32/116067_2.png) [@Olefine](https://meta.discourse.org/u/Olefine)
#### Post date: [May 4, 2015, 1:07pm UTC](https://meta.discourse.org/t/editing-a-poll-with-votes-creates-inconsistent-state/28239/2 "2015-05-04T13:07:46Z")

</div>

@gerhard I can reproduce this bug. I’ll fix it and propose pull request.

---

<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: [May 6, 2015, 4:54pm UTC](https://meta.discourse.org/t/editing-a-poll-with-votes-creates-inconsistent-state/28239/3 "2015-05-06T16:54:03Z")

</div>

Just pushed a fix that properly reset all votes when the number of options changes since there’s no **easy** way of “_merging_” options when they might be added/removed/sorted.

This shouldn’t be too much of a problem since this is only allowed for the first 5 minutes.

[https://github.com/discourse/discourse/commit/033761d2f629f45d8409ce7c5a547ff30ebb3543](https://github.com/discourse/discourse/commit/033761d2f629f45d8409ce7c5a547ff30ebb3543)

---

<div class="post-metadata">

### Author: ![Olefine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/olefine/32/116067_2.png) [@Olefine](https://meta.discourse.org/u/Olefine)
#### Post date: [May 6, 2015, 6:17pm UTC](https://meta.discourse.org/t/editing-a-poll-with-votes-creates-inconsistent-state/28239/4 "2015-05-06T18:17:21Z")

</div>

@zogstrip yep. You are right. I cant find easy way to merge old votes. Instead of storing poll’s data in html, we can use redis for store poll. What about this feature?

---

<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: [May 6, 2015, 9:16pm UTC](https://meta.discourse.org/t/editing-a-poll-with-votes-creates-inconsistent-state/28239/5 "2015-05-06T21:16:02Z")

</div>

> [@Olefine](#):
>
> Instead of storing poll’s data in html

Not sure what you mean by that.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [May 7, 2015, 12:22am UTC](https://meta.discourse.org/t/editing-a-poll-with-votes-creates-inconsistent-state/28239/6 "2015-05-07T00:22:44Z")

</div>


