Added dictfield check for Int keys

Fixes #371
This commit is contained in:
Ross Lawley 2011-11-28 07:05:54 -08:00
parent e1bb453f32
commit 208a467b24
2 changed files with 6 additions and 1 deletions

View File

@ -552,7 +552,9 @@ class DictField(ComplexBaseField):
if not isinstance(value, dict):
self.error('Only dictionaries may be used in a DictField')
if any(('.' in k or '$' in k) for k in value):
if any(k for k in value.keys() if not isinstance(k, basestring)):
self.error('Invalid dictionary key - documents must have only string keys')
if any(('.' in k or '$' in k) for k in value.keys()):
self.error('Invalid dictionary key name - keys may not contain "."'
' or "$" characters')
super(DictField, self).validate(value)

View File

@ -636,6 +636,9 @@ class FieldTest(unittest.TestCase):
post.info = {'the.title': 'test'}
self.assertRaises(ValidationError, post.validate)
post.info = {1: 'test'}
self.assertRaises(ValidationError, post.validate)
post.info = {'title': 'test'}
post.save()