Opened 9 years ago

Closed 9 years ago

Last modified 6 years ago

#25604 closed New feature (fixed)

Add --check flag to makemigrations; return 0 exit status for no new migrations

Reported by: Jon Dufresne 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

Django developers discussion: https://groups.google.com/forum/#!msg/django-developers/zczdY6c9KSg/ZXCXQsGDDAAJ

Proposal: add --check flag to the makemigrations management command. This flag will return 0 if no new migrations will be created. It will return non-zero if models contain changes without migrations. This will deprecrate the --exit flag originally discussed here: https://groups.google.com/forum/#!topic/django-developers/I3M6B-wYYd8/discussion. The problem with --exit is that it return the opposite exit status from what continuous integration servers typically expect.

My use case:

Continuous integration server check's developers' commits for correctness. One aspect of correctness is that all model changes have migrations.

In shell scripting and CI servers an exit status of 0 indicates true/pass and an exit status of non-zero indicates false/failure.

Therefore, the command should return 0 when everything is OK and correct and non-zero otherwise. Commits are correct when all model changes are accounted for.

The current --exit behavior, returns non-zero when everything is correct. To account for this in CI, one must negate the exit status with !, this goes against conventional behavior.

Further, if something goes terribly wrong and there is an unhandled exception, negating the exit status will make the CI stage appear to pass. This is backwards! CI can't tell the difference between "all changes accounted for" and "Python had an unhandled exception".

Change History (6)

comment:2 by Tim Graham, 9 years ago

Triage Stage: UnreviewedReady for checkin

comment:3 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 3c7d2ee:

Fixed #25604 -- Added makemigrations --check option.

Command exits with non-zero status if changes without migrations exist.

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

In e0910dcc:

Refs #25604 -- Removed makemigrations --exit option per deprecation timeline.

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

In b98dc170:

Refs #25604 -- Removed docs for makemigrations --exit.

Follow up to e0910dcc9283cd8f782cb97836c291f6f395f3f0.

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

In b749c356:

[2.0.x] Refs #25604 -- Removed docs for makemigrations --exit.

Follow up to e0910dcc9283cd8f782cb97836c291f6f395f3f0.
Backport of b98dc1706e9c63a4cc7d061a3d8a95f6cbf5e950 from master

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