1. Waldemar Kornewald
  2. djangotoolbox


Jonas Haag  committed 1db4a18

Fix #39: Don't call convert_value_from_db for fields' default values
(which don't come from the database)

  • Participants
  • Parent commits 81c7e4b
  • Branches default

Comments (0)

Files changed (3)

File djangotoolbox/db/basecompiler.py

View file
             value = entity.get(field.column, NOT_PROVIDED)
             if value is NOT_PROVIDED:
                 value = field.get_default()
+            else:
+                value = self.convert_value_from_db(field.db_type(connection=self.connection), value)
             if value is None and not field.null:
                 raise IntegrityError("Non-nullable field %s can't be None!" % field.name)
-            value = self.convert_value_from_db(field.db_type(connection=self.connection), value)
         return result

File djangotoolbox/fields.py

View file
 __all__ = ('RawField', 'ListField', 'DictField', 'SetField',
            'BlobField', 'EmbeddedModelField')
 class _HandleAssignment(object):
     A placeholder class that provides a way to set the attribute on the model.
         if item_field is None:
             item_field = RawField()
         self.item_field = item_field
-        default = kwargs.get('default', None if kwargs.get('null') else ())
+        default = kwargs.get('default', None if kwargs.get('null') else EMPTY_ITER)
         if default is not None and not callable(default):
             # ensure a new object is created every time the default is accessed
             kwargs['default'] = lambda: self._type(default)

File djangotoolbox/tests.py

View file
         self.assertNotEqual(dt, None)
         self.assertGreater(DictModel.objects.get().auto_now['a'], dt)
-        # This shouldn't raise an error becaues the default value is
-        # an empty dict
+        item.delete()
+        # Saving empty dicts shouldn't throw errors
+        # Regression tests for djangoappengine issue #39
+        DictModel.add_to_class('new_dict_field', DictField())
+        DictModel.objects.get()
     @unittest.skip('Fails with GAE SDK, but passes on production')
     def test_Q_objects(self):