diff mbox

[2/2] forms: 'False' != False

Message ID 20161223194335.30027-2-stephen@that.guru
State Accepted
Headers show

Commit Message

Stephen Finucane Dec. 23, 2016, 7:43 p.m. UTC
Forms cast boolean values to strings, and attempting to coerce using the
'bool' function does not correctly return them to true boolean values.
Correct this by doing a string comparison instead.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: 0abde97aa ("forms: Use TypedChoiceField")
---
 patchwork/forms.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Stephen Finucane Dec. 23, 2016, 11:06 p.m. UTC | #1
On Fri, 2016-12-23 at 19:43 +0000, Stephen Finucane wrote:
> Forms cast boolean values to strings, and attempting to coerce using
> the
> 'bool' function does not correctly return them to true boolean
> values.
> Correct this by doing a string comparison instead.
> 
> Signed-off-by: Stephen Finucane <stephen@that.guru>
> Fixes: 0abde97aa ("forms: Use TypedChoiceField")

Quick merge to fix the tests.
diff mbox

Patch

diff --git a/patchwork/forms.py b/patchwork/forms.py
index 56f1d86..f42a224 100644
--- a/patchwork/forms.py
+++ b/patchwork/forms.py
@@ -178,9 +178,10 @@  class MultiplePatchForm(forms.Form):
     action = 'update'
     state = OptionalModelChoiceField(queryset=State.objects.all())
     archived = OptionalBooleanField(
-        choices=[('*', 'no change'), (True, 'Archived'),
-                 (False, 'Unarchived')],
-        coerce=bool, empty_value='*')
+        choices=[('*', 'no change'), ('True', 'Archived'),
+                 ('False', 'Unarchived')],
+        coerce=lambda x: x == 'True',
+        empty_value='*')
 
     def __init__(self, project, *args, **kwargs):
         super(MultiplePatchForm, self).__init__(*args, **kwargs)