Skip to content

Commit

Permalink
Log error and exit 1 when invalid IDs are provided via -d --ids
Browse files Browse the repository at this point in the history
  • Loading branch information
cslzchen committed Aug 19, 2019
1 parent ffefa83 commit 224789b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions scripts/populate_institutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ def main():

if not update_all and not update_ids:
logger.error('Nothing to update or create. Please either specify a list of institutions '
'using --id or run for all with --all')
'using --ids or run for all with --all')
sys.exit(1)
elif update_all:
institutions_to_update = institutions
else:
institutions_to_update = [inst for inst in institutions if inst['_id'] in update_ids]
if len(institutions_to_update) < len(update_ids):
logger.warning('One or more institutions provided via -i or --ids do not match any '
'existing records, which have been skipped.')
diff_list = list(set(update_ids) - set([inst['_id'] for inst in institutions_to_update]))
if diff_list:
logger.error('One or more institution ID(s) provided via -i or --ids do not match any '
'existing records: {}.'.format(diff_list))
sys.exit(1)

init_app(routes=False)
with transaction.atomic():
Expand Down

0 comments on commit 224789b

Please sign in to comment.