Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

cdbennett
Copy link

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
Contributor

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

@cdbennett
Copy link
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
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
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