Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow tw2.sqla to set attributes to None or "".

  • Loading branch information...
commit 3863e440ddcd92fc09f8b46e1add97ac27bb6820 1 parent 11dfbc5
Ralph Bean ralphbean authored
Showing with 20 additions and 6 deletions.
  1. +18 −0 tests/test_utils.py
  2. +2 −6 tw2/sqla/utils.py
18 tests/test_utils.py
View
@@ -54,6 +54,24 @@ def test_from_dict_new(self):
assert(e.name == 'bazaar')
assert(len(e.others) == 0)
+ def test_from_dict_modify_to_none(self):
+ # Do this to set up an object with name => 'bazaar'
+ self.test_from_dict_new()
+
+ # Now try to modify that object and set its name to None
+ d = {
+ 'id': 2,
+ 'name': None,
+ }
+ x = self.DBTestCls1.query.filter_by(id=2).first()
+ e = twsu.from_dict(x, d)
+ if hasattr(self, 'session'):
+ self.session.flush()
+
+ eq_(e.id, 2)
+ eq_(e.name, None)
+ eq_(len(e.others), 0)
+
##
## Not sure if this test should even be possible, but its sure broken now
##
8 tw2/sqla/utils.py
View
@@ -34,12 +34,8 @@ def from_dict(obj, data, protect_prm_tamp=True):
protect_prm_tamp=protect_prm_tamp
)
elif key not in pk_props:
- if value or type(value) in (bool, int):
- # Ignore None and '', but we do want to explicitly
- # set 'False' or '0' if its a boolean/integer.
- setattr(obj, key, value)
- else:
- pass
+ setattr(obj, key, value)
+
return obj
Please sign in to comment.
Something went wrong with that request. Please try again.