Skip to content

Commit

Permalink
Revert "Revert "make it so that merge_related also updates fields tha…
Browse files Browse the repository at this point in the history
…t match on the key""

This reverts commit fc1ca39.
  • Loading branch information
jamesturk committed Sep 17, 2015
1 parent f17e8e2 commit d550e02
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pupa/importers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,14 @@ def _update_related(self, obj, related, subfield_dict):
# add it to new_items
for item in items:
key = tuple(item.get(k) for k in keylist)
print(key, keyed_dbitems.keys())
dbitem = keyed_dbitems.get(key)
if not dbitem:
new_items.append(item)
else:
pass
# update dbitem
for fname, val in item.items():
setattr(dbitem, fname, val)
dbitem.save()

# import anything that made it to new_items in the usual fashion
self._create_related(obj, {field: new_items}, subfield_dict)
Expand Down
6 changes: 6 additions & 0 deletions pupa/tests/importers/test_jurisdiction_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ def test_jurisdiction_merge_related():
tj.legislative_sessions.append({'identifier': '2017', 'name': '2017 Session'})
ji.import_item(tj.as_dict())
assert LegislativeSession.objects.count() == 3

# and test that the non-identifier fields actually update
tj.legislative_sessions.append({'identifier': '2016', 'name': 'updated'})
ji.import_item(tj.as_dict())
assert LegislativeSession.objects.count() == 3
assert LegislativeSession.objects.get(identifier='2016').name == 'updated'

0 comments on commit d550e02

Please sign in to comment.