1. Bitbucket
  2. Public Issue Tracker
  3. master
  4. Issues


Issue #624 invalid

0 and None are being shown as an empty string in fields

Anonymous created an issue

When trying to use a HiddenField for an id I noticed that its treating 0 as "" as well as doing the same for None. This shows up in atleast IntegerField as well. Included below is a unit test showing the problem.



import unittest from wtforms import Form, HiddenField

class Foo(Form): id = HiddenField()

class TestHiddenField(unittest.TestCase): def setUp(self): self.f = Foo()

def test_none_data_is_blank(self):
    self.f.id.data = None
    self.assertEqual(str(self.f.id),'<input id="id" name="id" type="hidden" value="" />')

def test_0_data_is_0(self):
    self.f.id.data = 0
    self.assertEqual(str(self.id),'<input id="id" name="id" type="hidden" value="0" />')

suite = unittest.TestLoader().loadTestsFromTestCase(TestHiddenField) unittest.TextTestRunner(verbosity=2).run(suite)


this gives me


test_0_data_is_0 (main.TestHiddenField) ... FAIL test_none_data_is_blank (main.TestHiddenField) ... ok

====================================================================== FAIL: test_0_data_is_0 (main.TestHiddenField)

Traceback (most recent call last): File "C:\eclipse\workspace\renderranch\test.py", line 17, in test_0_data_is_0 self.assertEqual(str(self.id),'<input id="id" name="id" type="hidden" value="0" />') AssertionError: '<bound method TestHiddenField.id of <main.TestHiddenField testMethod=test_0_data_is_0>>' != '<input id="id" name="id" type="hidden" value="0" />'

Ran 2 tests in 0.000s

FAILED (failures=1)


Comments (2)

  1. Log in to comment