Skip to content

Commit bb1f6ad

Browse files
committed
[#81] Update warning to suggest that duplicate IDs may be the problem
1 parent 6b3ba79 commit bb1f6ad

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

flattentool/input.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,11 @@ def merge(base, mergee, debug_info=None):
8686
elif isinstance(value, dict) and isinstance(base[key], dict):
8787
merge(base[key], value, debug_info)
8888
elif base[key] != value:
89-
warn('Conflict when merging {} in sheet {}: {} != {}'.format(
90-
key, debug_info.get('sheet_name'), base[key], value))
89+
id_info = 'id "{}"'.format(debug_info.get('id'))
90+
if debug_info.get('root_id'):
91+
id_info = '{} "{}", '.format(debug_info.get('root_id'), debug_info.get('root_id_or_none'))+id_info
92+
warn('Conflict when merging field "{}" for {} in sheet {}: "{}" != "{}". If you were not expecting merging you may have a duplicate ID.'.format(
93+
key, id_info, debug_info.get('sheet_name'), base[key], value))
9194
else:
9295
base[key] = value
9396

@@ -165,7 +168,16 @@ def unflatten(self):
165168
if root_id_or_none not in main_sheet_by_ocid:
166169
main_sheet_by_ocid[root_id_or_none] = TemporaryDict('id')
167170
if 'id' in unflattened and unflattened['id'] in main_sheet_by_ocid[root_id_or_none]:
168-
merge(main_sheet_by_ocid[root_id_or_none][unflattened.get('id')], unflattened, {'sheet_name':sheet_name})
171+
merge(
172+
main_sheet_by_ocid[root_id_or_none][unflattened.get('id')],
173+
unflattened,
174+
{
175+
'sheet_name': sheet_name,
176+
'root_id': self.root_id,
177+
'root_id_or_none': root_id_or_none,
178+
'id': unflattened.get('id')
179+
}
180+
)
169181
else:
170182
main_sheet_by_ocid[root_id_or_none].append(unflattened)
171183

flattentool/tests/test_input_SpreadsheetInput_unflatten_mulitplesheets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def test_conflicting_rollup(self, recwarn):
323323
]
324324
# We should have a warning about the conflict
325325
w = recwarn.pop(UserWarning)
326-
assert 'Conflict when merging testB in sheet testA: 4 != 5' in text_type(w.message)
326+
assert 'Conflict when merging field "testB" for ocid "1", id "2" in sheet testA: "4" != "5"' in text_type(w.message)
327327

328328

329329
class TestUnflattenEmpty(object):

0 commit comments

Comments
 (0)