Opened 10 years ago

Last modified 9 years ago

#969 closed defect

gmg user commands don't fail gracefully for non existant users — at Version 4

Reported by: ayleph Owned by:
Priority: trivial Milestone: 0.9.0
Component: programming Keywords: gmg, delete, user, deleteuser
Cc: berkerpeksag Parent Tickets:

Description (last modified by Elrond)

Attempt to delete a non-existent user using bin/gmg deleteuser and you'll get a Traceback similar to below.

$ bin/gmg deleteuser idontexist
Traceback (most recent call last):
  File "bin/gmg", line 9, in <module>
    load_entry_point('mediagoblin==0.7.1.dev', 'console_scripts', 'gmg')()
  File "/path/to/mediagoblin/mediagoblin/gmg_commands/__init__.py", line 124, in main_cli
    args.func(args)
  File "/path/to/mediagoblin/mediagoblin/gmg_commands/users.py", line 132, in deleteuser
    username=unicode(args.username.lower())).one()
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/query.py", line 2329, in one
sqlalchemy.orm.exc.NoResultFound: No row was found for one()

Same problem exists for other commands in users.py.

Change History (4)

comment:1 by ayleph, 10 years ago

Owner: set to ayleph
Status: newin_progress

Elrond suggested the following change, which tested out fine for existing and non-existing users on my system.

mediagoblin/gmg_commands/users.py:

@@ -129,7 +129,7 @@ def deleteuser(args):
     db = mg_globals.database
 
     user = db.User.query.filter_by(
-        username=unicode(args.username.lower())).one()
+        username=unicode(args.username.lower())).first()
     if user:
         user.delete()
         print 'The user %s has been deleted' % args.username
Last edited 10 years ago by ayleph (previous) (diff)

comment:3 by ayleph, 10 years ago

Milestone: 0.8.0
Resolution: fixed
Status: reviewclosed

comment:4 by Elrond, 10 years ago

Description: modified (diff)
Resolution: fixed
Status: closedaccepted
Summary: gmg deleteuser doesn't fail gracefullygmg user commands don't fail gracefully for non existant users

We just realized, that users.py is affected globally.

Notes:

  1. Wait until py3 merge is over!
  2. Instead of doing unicode(...) (or six.text_type) in the db query, try doing a type=six.text_type in the .add_argument of the parser setup, so that the parser already does the typing for us.
Note: See TracTickets for help on using tickets.