Opened 8 years ago

Closed 8 years ago

#27522 closed Bug (fixed)

./manage runserver --nostatic doesn't return a traceback

Reported by: Jeroen van Veen Owned by: nobody
Component: Core (Management commands) Version: dev
Severity: Normal Keywords: runserver nostatic
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Jeroen van Veen)

When running ./manage runserver --nostatic, I expect a traceback to be returned when
a syntax error occurs, and I expect the autoreloader still to be available. Instead, the
runserver command exits like:

usage: manage.py runserver [-h] [--version] [-v {0,1,2,3}]
                           [--settings SETTINGS] [--pythonpath PYTHONPATH]
                           [--traceback] [--no-color] [--ipv6] [--nothreading]
                           [--noreload]
                           [addrport]
manage.py runserver: error: unrecognized arguments: --nostatic

Ticket: https://github.com/wearespindle/django/tree/ticket_27522

Change History (13)

comment:1 by Jeroen van Veen, 8 years ago

This is a workaround:

--- django/core/management/__init__.py.orig	2016-11-22 09:58:38.806209538 +0100
+++ django/core/management/__init__.py	2016-11-22 10:10:00.229652313 +0100
@@ -323,6 +323,10 @@
                     apps.all_models = defaultdict(OrderedDict)
                     apps.app_configs = OrderedDict()
                     apps.apps_ready = apps.models_ready = apps.ready = True
+                    # Execute the runserver command, but strip off additional
+                    # parameters that cause the argument parser to fail.
+                    self.fetch_command(subcommand).run_from_argv(self.argv[0:2])
+                    return
 
             # In all other cases, django.setup() is required to succeed.
             else:
Last edited 8 years ago by Jeroen van Veen (previous) (diff)

comment:2 by Jeroen van Veen, 8 years ago

Description: modified (diff)

comment:3 by Jeroen van Veen, 8 years ago

Please let me know if it needs some more work! :)

comment:4 by Jeroen van Veen, 8 years ago

Triage Stage: UnreviewedAccepted

comment:5 by Jeroen van Veen, 8 years ago

Version: 1.101.8

comment:6 by Jeroen van Veen, 8 years ago

Keywords: runserver nostatic added

comment:7 by Jeroen van Veen, 8 years ago

Description: modified (diff)
Version: 1.8master

comment:8 by Tim Graham, 8 years ago

I can reproduce the problem. Without taking a closer look, I'm not sure about the solution. If you could write a test, that would certainly help.

comment:9 by Tim Graham, 8 years ago

Description: modified (diff)
Has patch: set
Needs tests: set

PR (currently without tests)

comment:10 by Jeroen van Veen, 8 years ago

Description: modified (diff)
Needs tests: unset

I'm trying to figure out where this test should be placed.

comment:11 by Tim Graham, 8 years ago

Needs tests: set

Some tests for runserver are in admin_scripts/tests.py. It might be infeasible to test this (for example, fe6ddb837d18bd4e71cd22fc18272d31478b19f2 lacked tests) but it would be nice to try.

comment:13 by Tim Graham, 8 years ago

Needs tests: unset
Triage Stage: AcceptedReady for checkin

Steps to reproduce: modify a Django project to have a syntax error and run runserver --nostatic. You should see the SyntaxError traceback (after this fix) rather than manage.py runserver: error: unrecognized arguments: --nostatic.

I don't think it's feasible to write a test for this so I'll commit the change without one.

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

Resolution: fixed
Status: assignedclosed

In ed4264c5:

Fixed #27522 -- Fixed runserver autoreload when using staticfile's options.

On a SyntaxError, made runserver exit with a stacktrace when using
contrib.staticfiles's runserver options such as --nostatic.

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