Skip to content

Commit 549b5b3

Browse files
committed
Handle duplicated keys before doing transform's field_renamings #541
Signed-off-by: Chin Yeung Li <tli@nexb.com>
1 parent 0806554 commit 549b5b3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/attributecode/cmd.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,19 @@ def transform(location, output, configuration, worksheet, quiet, verbose): # NO
845845
elif location.endswith('.xlsx'):
846846
new_data, errors = transform_excel(location, worksheet)
847847

848+
data_keys = new_data[0].keys() if new_data else []
849+
transformer_keys = transformer.field_renamings.keys()
850+
dup_keys = []
851+
852+
for key in transformer_keys:
853+
if key in data_keys:
854+
dup_keys.append(key)
855+
856+
if dup_keys:
857+
msg = 'The following field(s) in the input data are duplicated in the transformer field renamings: {dup_keys}.\nPlease correct and re-run.'.format(**locals())
858+
click.echo(msg)
859+
sys.exit(1)
860+
848861
if not errors:
849862
updated_data, errors = transform_data(new_data, transformer)
850863

0 commit comments

Comments
 (0)