Code

#18387 closed New feature (fixed)

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

Reported by: claudep Owned by: nobody
Component: Core (Management commands) Version: master
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 claudep 23 months ago.
Add raise_on_error option
18387-2.diff (8.1 KB) - added by claudep 23 months ago.
Alternative solution without additional parameter
18387-3.diff (10.0 KB) - added by claudep 23 months ago.
Patch 2 + complementary docs

Download all attachments as: .zip

Change History (6)

Changed 23 months ago by claudep

Add raise_on_error option

Changed 23 months ago by claudep

Alternative solution without additional parameter

comment:1 Changed 23 months ago by claudep

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().

Changed 23 months ago by claudep

Patch 2 + complementary docs

comment:2 Changed 23 months ago by akaariai

  • Triage Stage changed from Accepted to Ready for checkin

LGTM

comment:3 Changed 23 months ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.