Opened 13 years ago

Closed 13 years ago

#18387 closed New feature (fixed)

Provide a way to skip sys.exit() when using call_command()

Reported by: Claude Paroz Owned by: nobody
Component: Core (Management commands) Version: dev
Severity: Normal Keywords:
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

When running a management command from Python code with call_command, any CommandError raised in the execute method will call sys.exit(1). This is not always desirable, so we should provide a way to call call_command without this flaw.

This should also allow us to fix issues like #10200 painlessly.

Attachments (3)

18387-1.diff (3.2 KB ) - added by Claude Paroz 13 years ago.
Add raise_on_error option
18387-2.diff (8.1 KB ) - added by Claude Paroz 13 years ago.
Alternative solution without additional parameter
18387-3.diff (10.0 KB ) - added by Claude Paroz 13 years ago.
Patch 2 + complementary docs

Download all attachments as: .zip

Change History (6)

by Claude Paroz, 13 years ago

Attachment: 18387-1.diff added

Add raise_on_error option

by Claude Paroz, 13 years ago

Attachment: 18387-2.diff added

Alternative solution without additional parameter

comment:1 by Claude Paroz, 13 years ago

After discussion on #django-dev, added a new patch that does not add any new parameter to call_command, but move sys.exit(1) higher in the calling stack so that it is not used with call_command. Only commands run from command line will reach exit().

by Claude Paroz, 13 years ago

Attachment: 18387-3.diff added

Patch 2 + complementary docs

comment:2 by Anssi Kääriäinen, 13 years ago

Triage Stage: AcceptedReady for checkin

LGTM

comment:3 by Claude Paroz <claude@…>, 13 years ago

Resolution: fixed
Status: newclosed

In [f2b6763ad7cb281ca8699a9c3d532a82f965be4f]:

Fixed #18387 -- Do not call sys.exit during call_command.

Moved sys.exit(1) so as failing management commands reach it
only when running from command line.

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