Opened 10 years ago
Closed 9 years ago
#969 closed defect (fixed)
gmg user commands don't fail gracefully for non existant users
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 )
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.
Attachments (2)
Change History (16)
comment:1 by , 10 years ago
Owner: | set to |
---|---|
Status: | new → in_progress |
comment:2 by , 10 years ago
Owner: | removed |
---|---|
Status: | in_progress → review |
comment:3 by , 10 years ago
Milestone: | → 0.8.0 |
---|---|
Resolution: | → fixed |
Status: | review → closed |
comment:4 by , 10 years ago
Description: | modified (diff) |
---|---|
Resolution: | fixed |
Status: | closed → accepted |
Summary: | gmg deleteuser doesn't fail gracefully → gmg user commands don't fail gracefully for non existant users |
We just realized, that users.py is affected globally.
Notes:
- Wait until py3 merge is over!
- Instead of doing
unicode(...)
(orsix.text_type
) in the db query, try doing atype=six.text_type
in the.add_argument
of the parser setup, so that the parser already does the typing for us.
comment:5 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | accepted → closed |
I have used the type=sex.text_type
as suggested above in the parser setup. The rest of this bug looks to be resolved though, current master:
(mediagoblin)[jessica@macbook mediagoblin]$ ./bin/gmg deleteuser idontexist The user idontexist doesn't exist
As far as I can see that makes this issue closed as everything reported has been fixed. The fix I pushed is in a02de38. If I've missed anything feel free to re-open this issue or open a new issue with the specific issue.
comment:6 by , 10 years ago
Resolution: | fixed |
---|---|
Status: | closed → accepted |
Originally I opened the ticket when someone pointed out that deleteuser
was failing for a user that didn't exist. Elrond fixed that and merged it. Later we realized it applied to other commands as well, so we re-opened the ticket. This is still the case. The fix needs to be applied to the other commands.
For example, changepw
:
$ bin/gmg changepw idontexist mynewpassword ** Message: pygobject_register_sinkfunc is deprecated (GstObject) Traceback (most recent call last): File "bin/gmg", line 9, in <module> load_entry_point('mediagoblin==0.7.2.dev', 'console_scripts', 'gmg')() File "/path/to/mediagoblin/mediagoblin/gmg_commands/__init__.py", line 156, in main_cli args.func(args) File "/path/to/mediagoblin/mediagoblin/gmg_commands/users.py", line 115, in changepw username=six.text_type(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()
And makeadmin
:
$ bin/gmg makeadmin idontexist ** Message: pygobject_register_sinkfunc is deprecated (GstObject) Traceback (most recent call last): File "bin/gmg", line 9, in <module> load_entry_point('mediagoblin==0.7.2.dev', 'console_scripts', 'gmg')() File "/path/to/mediagoblin/mediagoblin/gmg_commands/__init__.py", line 156, in main_cli args.func(args) File "/path/to/mediagoblin/mediagoblin/gmg_commands/users.py", line 88, in makeadmin username=six.text_type(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()
comment:7 by , 10 years ago
Milestone: | 0.8.0 → 0.9.0 |
---|
Worth fixing, but can be bumped to next release, not a blocker for 0.8.0
comment:8 by , 9 years ago
Status: | accepted → review |
---|
I'm attaching a patch to changepw
and makeadmin
to prevent these unhandled exceptions when the user doesn't exist.
Regards,
Ben
by , 9 years ago
Attachment: | issue_696.patch added |
---|
comment:9 by , 9 years ago
I should mention that I've manually tested both valid and invalid users for changepw
and makeadmin
.
comment:10 by , 9 years ago
Cc: | added |
---|
Looks good to me, at a glance. CC'ing berker to consider pushing to master.
follow-up: 12 comment:11 by , 9 years ago
I couldn't apply the patch cleanly. Could you please fix merge conflicts?
+ print(u'The user %s doesn\'t exist.' % args.username)
Can you change %s to %r? The user 'foo' doesn't exist.
looks better to me. Same comment for other usages of %s.
+ type=six.text_type)
Clever! :)
Thanks!
comment:12 by , 9 years ago
I couldn't apply the patch cleanly. Could you please fix merge conflicts?
Oh, I see now that tsyesika's changes from earlier today modified this file after Sturm's patch was submitted. How exciting!
comment:13 by , 9 years ago
Thanks for the review Berker. I've resolved the conflict in the attached patch.
comment:14 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | review → closed |
The patch looks good, and it didn't break any patches that aren't already broken in master (I'd better look into those!)
Great work Sturm, thanks for the patch! And thanks for your review berker, as well as your contributions on this one ayleph!
Sometimes things take a while, but they make it... :)
Elrond suggested the following change, which tested out fine for existing and non-existing users on my system.
mediagoblin/gmg_commands/users.py: