From 9da03b739f19d43f195e6216f3469808fa67a191 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Fri, 9 May 2014 23:37:49 +0300 Subject: [PATCH] Convert media_ids to int safely. With this commit, "gmg deletemedia spam,12" will not raise ValueError anymore. --- mediagoblin/gmg_commands/deletemedia.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mediagoblin/gmg_commands/deletemedia.py b/mediagoblin/gmg_commands/deletemedia.py index ed1ca4e9..ab5a81f6 100644 --- a/mediagoblin/gmg_commands/deletemedia.py +++ b/mediagoblin/gmg_commands/deletemedia.py @@ -27,7 +27,10 @@ def parser_setup(subparser): def deletemedia(args): app = commands_util.setup_app(args) - media_ids = set(map(int, args.media_ids.split(','))) + media_ids = set([int(mid) for mid in args.media_ids.split(',') if mid.isdigit()]) + if not media_ids: + print 'Can\'t find any valid media ID(s).' + sys.exit(1) found_medias = set() filter_ids = app.db.MediaEntry.id.in_(media_ids) medias = app.db.MediaEntry.query.filter(filter_ids).all() -- 2.25.1