[Feature] On CommandError, sys.exit(1)

84 views
Skip to first unread message

Ben Liyanage

unread,
Oct 22, 2015, 5:20:18 AM10/22/15
to django-d...@googlegroups.com
Hey,

What do you guys think about this feature request?

> On CommandError, sys.exit(1)

It would be pretty easy to do the sys.exit(1) right here:

https://github.com/django/django/blob/df0a446fd4c864c003e4f941b5b7abd6f10c9427/django/core/management/__init__.py#L289

This would allow you to fail an automated build when migrations (or any other management command) failed.  Currently I see no way of doing that.

Beyond that, I noticed that the sys.exit(1) is not very consistently applied on the makemigrations management command (for example, it is not called when the --merge parameter is supplied).

I can do the PR for the CommandError thing (unless anyone sees a reason not to, or that would not work/there is a better place to put it).

--
Ben Liyanage | Software Engineer | Rentlytics, Inc.
Phone: (410) 336-2464 | Email: bliy...@rentlytics.com
1132 Howard Street, San Francisco CA 94107

bliy...@rentlytics.com

unread,
Oct 26, 2015, 2:01:17 PM10/26/15
to Django developers (Contributions to Django itself)
Is it ok if I do a PR on this?  This seems like it would be really useful for automation.

-Ben

Tim Graham

unread,
Oct 26, 2015, 2:21:17 PM10/26/15
to Django developers (Contributions to Django itself)
The place you linked to is ignoring CommandError when parsing arguments. I'm not sure under what conditions this happens (if at all) -- the Django tests don't cover it.

As far as I know, BaseCommand already does sys.exit(1) when there's an unhandled exception: https://github.com/django/django/blob/df0a446fd4c864c003e4f941b5b7abd6f10c9427/django/core/management/base.py#L289-L300

Could you clarify how to reproduce the problem you're seeing?

bliy...@rentlytics.com

unread,
Oct 27, 2015, 4:00:32 PM10/27/15
to Django developers (Contributions to Django itself)
Hm, let me check it out and get back to you.  We had some migrations that exited in failure, but with a non-0 exit status during our release.  I'll see if I can reproduce this this week.

-Ben
Reply all
Reply to author
Forward
0 new messages