Skip to content

Check for action arg before use (fix Python 3 error)#79

Closed
cdbennett wants to merge 1 commit intopython-gitlab:masterfrom
cdbennett:fix_python3_arg_action
Closed

Check for action arg before use (fix Python 3 error)#79
cdbennett wants to merge 1 commit intopython-gitlab:masterfrom
cdbennett:fix_python3_arg_action

Conversation

@cdbennett
Copy link
Copy Markdown

Check that the parsed action attribute exists before using it.
Previously, whenever the command-line tool was invoked on Python 3.4
without a bare-word argument, which is expected to be the action, the
program aborts with an AttributeError in cli.py on the line assigning
arg.action to action:

AttributeError: 'Namespace' object has no attribute 'action'

Check that the parsed `action` attribute exists before using it.
Previously, whenever the command-line tool was invoked on Python 3.4
without a bare-word argument, which is expected to be the action, the
program aborts with an AttributeError in cli.py on the line assigning
`arg.action` to `action`:

    AttributeError: 'Namespace' object has no attribute 'action'
@gpocentek
Copy link
Copy Markdown
Contributor

Could you give an example of a command that would generate this error? Thanks.

@cdbennett
Copy link
Copy Markdown
Author

This issue occurs whenever there is no positional ("bareword") argument given to the program. For instance, with no arguments at all gitlab will hit it:

$ gitlab
Traceback (most recent call last):
  File "C:\Python34\Scripts\gitlab-script.py", line 9, in <module>
    load_entry_point('python-gitlab==0.9.1', 'console_scripts', 'gitlab')()
  File "C:\Python34\lib\site-packages\python_gitlab-0.9.1-py3.4.egg\gitlab\cli.py", line 275, in main
AttributeError: 'Namespace' object has no attribute 'action'

It will also occur if you provide option arguments, but still don't provide a positional argument (one that is not an option flag) as in gitlab -v:

$ gitlab -v
Traceback (most recent call last):
  File "C:\Python34\Scripts\gitlab-script.py", line 9, in <module>
    load_entry_point('python-gitlab==0.9.1', 'console_scripts', 'gitlab')()
  File "C:\Python34\lib\site-packages\python_gitlab-0.9.1-py3.4.egg\gitlab\cli.py", line 275, in main
AttributeError: 'Namespace' object has no attribute 'action'

This test was performed with the #78 (fix_python3_sort_types) fix applied -- otherwise Python 3 will fail earlier in the program before this point is reached.

@gpocentek
Copy link
Copy Markdown
Contributor

I just push commit 7c38ef6 which should fix for this bug. It uses the argparse features instead of providing a custom test. Could you test it to make sure it behaves as you would expect? Thanks.

@cdbennett
Copy link
Copy Markdown
Author

Verified fixed with commit 7c38ef6. Thanks.

@cdbennett cdbennett closed this Jan 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants