kiddouk/redisco — pull request #9 by jkbr (2012-08-26 19:18:56+00:00)
Title: Apply type validation to falsy values as well

For example, this instance would previously get saved:

class Person(models.Model):
age = models.IntegerField()

>>> p = Person(age=[])
>>> p.save()
True

…and fail with a value error when loaded:

>>> Person.objects.get_by_id(p.id)
Traceback (most recent call last):
File "", line 1, in
Person.objects.get_by_id(p.id)
File "redisco/models/managers.py", line 40, in get_by_id
return self.get_model_set().get_by_id(id)
File "redisco/models/modelset.py", line 63, in get_by_id
return self._get_item_with_id(id)
File "redisco/models/modelset.py", line 276, in _get_item_with_id
instance.id = str(id)
File "redisco/models/base.py", line 328, in id
att.__set__(self, att.typecast_for_read(stored_attrs[att.name]))
File "redisco/models/attributes.py", line 153, in typecast_for_read
return int(value)
ValueError: invalid literal for int() with base 10: '[]'

With this patch:

>>> p = Person(age=[])
>>> p.save()
[('age', 'bad type')]