Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#25838 closed Cleanup/optimization (fixed)

./manage.py shell creates unnecessary nested exceptions

Reported by: Baptiste Mispelon Owned by: nobody
Component: Core (Management commands) Version: dev
Severity: Normal Keywords:
Cc: jon.dufresne@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Steps to reproduce (using Python 3):

  • Open a python shell with ./manage.py shell
  • raise an exception with raise Exception

Notice how the exception is nested with another one:

>>> raise Exception
Traceback (most recent call last):
  File "./django/core/management/commands/shell.py", line 67, in handle
    raise ImportError
ImportError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
Exception

Change History (8)

comment:1 by Baptiste Mispelon, 8 years ago

Changing the logic in core/management/shell.py from

try:
    if options['plain']:
        # Don't bother loading IPython, because the user wants plain Python.
        raise ImportError

    self.run_shell(shell=options['interface'])
except ImportError:
    # do a bunch of stuff

to:

try:
    if options['plain']:
        # Don't bother loading IPython, because the user wants plain Python.
        raise ImportError

    self.run_shell(shell=options['interface'])
except ImportError:
    pass
else:
    return
# do a bunch of stuff

Seems to fix the issue for me

comment:2 by Florian Apolloner, 8 years ago

I'd rather add "plain" to the list of available shells all time, so we just need a simple loop over all the shells (if "plain" is always added as last one, there should be no need for extra fallback handling etc…)

comment:3 by Tim Graham, 8 years ago

Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

comment:4 by Jon Dufresne, 8 years ago

Cc: jon.dufresne@… added
Has patch: set

comment:5 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: newclosed

In f1628f6:

Fixed #25838 -- Added "python" as an interface to the shell command.

Deprecates the "--plain" option.

comment:6 by Chris Jerdonek, 8 years ago

Thanks for fixing this! To prevent regressions, should a test also have been added checking that the exception chain doesn't have spurious entries?

comment:7 by Tim Graham, 8 years ago

I'm not sure if the shell command can be tested, currently it doesn't have any tests. Maybe it would be feasible after #25680 is fixed, but the risk of this regression seems low, especially because this command doesn't receive much innovation.

comment:8 by Tim Graham <timograham@…>, 7 years ago

In f65b1ae:

Refs #25838 -- Removed the deprecated shell --plain option.

Note: See TracTickets for help on using tickets.
Back to Top