Commits

Anonymous committed 9df414b Draft

fix bug #17: coerce types in model.__init__()

  • Participants
  • Parent commits f20218f

Comments (0)

Files changed (2)

File dynamodb_mapper/model.py

                 default = kwargs.get(name)
             else:
                 default = defaults[name] if name in defaults else None
-            setattr(self, name, _get_default_value(type_, default, name=name))
+            value = _dynamodb_to_python(type_, default) # just in case, ensure types. help migration from 'from_dict'
+            value = _get_default_value(type_, value, name=name)
+            setattr(self, name, value)
 
         # instanciate the migrator only once per model *after* initialization
         if isinstance(cls.__migrator__, type):

File dynamodb_mapper/tests/test_model.py

         self.assertEqual(1, d.id)
         self.assertEqual(u"Knee-deep in the Dead", d.name)
 
+    def test_init_from_unicode_kwargs(self):
+        # regression test for bug #17
+        kwargs = {
+            u'id': u'1',
+            u'name': u'Knee-deep in the Dead',
+        }
+
+        d = DoomEpisode(**kwargs)
+        self.assertEqual({}, d._raw_data)
+        self.assertEqual(1, d.id)
+        self.assertEqual(u"Knee-deep in the Dead", d.name)
+
     def test_build_from_dict(self):
         #FIXME: can it be removed as this feature is implicitly tested elsewhere ?
         d_dict = {"id": 1, "name": "Knee-deep in the Dead"}