Skip to content

Commit

Permalink
Didn't quite fix the None child model issue before. Fixed Now.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmvrbanac committed Oct 15, 2018
1 parent 5048f21 commit 5374415
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions alchemize/transmute.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ def transmute_to(cls, mapped_model, to_string=True, assign_all=False,
encoder = encoder or json
encoder_kwargs = encoder_kwargs or {}

if not mapped_model:
return None

for name, attr in get_normalized_map(mapped_model).items():
attr_value = None

Expand Down
8 changes: 8 additions & 0 deletions spec/json_transmuter.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,3 +631,11 @@ class TestMappedModel(JsonMappedModel):
result = JsonTransmuter.transmute_from(test_json, TestMappedModel)

expect(result.test).to.equal('')

def transmute_to_with_empty_submodel(self):
model = TestChildMapping()
model.child = None

result = JsonTransmuter.transmute_to(model, to_string=False)

expect(result.get('child')).to.be_none()

0 comments on commit 5374415

Please sign in to comment.